mIRC Home    About    Download    Register    News    Help

Print Thread
Hash Rename #153390 15/07/06 05:22 PM
Joined: Jan 2003
Posts: 3,012
KingTomato Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
I'm not sure if it's beyond the scope of a hash table to do this, or it's just plain laziness or (presumed) efficiency on my part, but I'd like to see a /hrename method.

My reasoning: I have a bot with a hefty seen table, and I've made a routine to update the hash items to include one more column. Now, I know I've already iterated through the hash listing once, but I always like to double check before I mess something up so I've created a temp table and "applied" the changes to it, then viewed the table to make sure it went ok. Now that I've confirmed it worked, I have to iterate again to change the real table. Would be kind of nifty just freeing my previous, and having the changed table take over so to speak.

Again, it's just redundancy on my part, but I'm sure it could have some other features that someone with more intuition than I have. It may be hard to impliment, may not--I'm not sure. Just kind of a cool feature I thought. Feel free to give every reason why it's useless, absurd, and unnecessary.

Thanks as always. wink


-KingTomato
Re: Hash Rename #153391 15/07/06 07:12 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
This could be a useful command.

Until it is implemented you can 'rename' a hash table by using this alias:

;Usage: /hrename <oldname> <newname>

Code:
alias hrename {
  ;1=oldname 2=newname
  if (!$2) { echo -a /hrename &lt;oldname&gt; &lt;newname&gt; | return }
  var %h.size = $hget($1).size
  var %h.file = temp $+ $ctime $+ .htb
  hsave -sb $1 %h.file
  hfree -s $1
  hmake -s $2 %h.size
  hload -sb $2 %h.file
  echo -a $1 data backed-up as %h.file
}


(untested)

-genius_at_work

Re: Hash Rename #153392 16/07/06 12:05 AM
Joined: Jan 2006
Posts: 468
symphony Offline
Fjord artisan
Offline
Fjord artisan
Joined: Jan 2006
Posts: 468
I agree with genius_at_work. This is completely scriptable.

Here is my tested code
Code:
  ALIAS hren { 
  IF ($0 == 2) { 
    IF $hget($1) { 
      VAR %t1.size $hget($1).size 
      HSAVE -o $1 temp.data. [ $+ [ $1 ] $+ ] .hsh 
    } 
    ELSE { 
      ECHO 4 -a /hren error: Table $1 does not exist 
      HALT 
    } 
    IF $hget($2) { ECHO 4 -a /hren error: Table $2 alread exists } 
    ELSE { 
      HMAKE -s $2 %t1.size 
      HLOAD -s $2 temp.data. [ $+ [ $1 ] $+ ] .hsh 
      HFREE -s $1 %t1.size 
    } 
    ECHO 4 -a /hren: Successfully completed operation. 
  } 
  ELSE {  ECHO 4 -a Syntax Error: /hren &lt;table1&gt; &lt;table2&gt; } 
} 
 

Edit -fixed typos-

Last edited by Symphony; 16/07/06 12:28 AM.
Re: Hash Rename #153393 16/07/06 03:46 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
I agree with genius_at_work. This is completely scriptable.
Here is my tested code


It isnt completely scriptable, and you didnt test your code overly hard.

Code:
bset &amp;binvar 1000000 0 | hadd -mb table1 item1 &amp;binvar
var %crlf = $crlf      | hadd -m table1 item2 %crlf
var %num = 99          | hadd -mz table1 item3 %num
var %true = $true      | hadd -mu10 table1 item4 %num


Not one of these items survive your code.

* While i dont really have a need for this command, i dont think its unworthy of a command.
* Of course if your working on your on hashtables, you could always just work your own naming system out, like using....
%hashtable.name then just /set %hahstable.name table1 and later /set %hahstable.name table2 or more complexely using a custom alias like $hashtable.name and return the active table.

Re: Hash Rename #153394 16/07/06 07:21 AM
Joined: Jan 2006
Posts: 468
symphony Offline
Fjord artisan
Offline
Fjord artisan
Joined: Jan 2006
Posts: 468
Hmm, you are right. Binvar, and identifiers..