mIRC Home    About    Download    Register    News    Help

Print Thread
#200773 11/06/08 03:16 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
What's the easiest way to rename items in a hash? Should I read in the item data by the item name, then save it under the new item name, and finally delete the old item name?


I registered; you should too.
Joined: Jul 2006
Posts: 4,146
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,146
I think you should try to test thing yourself, there isn't so many way to do this, simply try what you're saying here.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2007
Posts: 334
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Aug 2007
Posts: 334
1: why would you want to change the names?
and 2: the copying then deleting works fine


This is not the signature you are looking for
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
This may not be what you're asking about, but it's an idea...

Code:
alias test { 
  var %i = 1,%h = $hget(Tablename,0).item
  hdel Tablename Originaltext 1
  while %i <= %h { 
    hadd Tablename Newtext 2
    inc %i 
  } 
}


Perhaps /hsave and /hload may well be used in this case...

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Originally Posted By: Tomao
This may not be what you're asking about, but it's an idea...

Code:
alias test { 
  var %i = 1,%h = $hget(Tablename,0).item
  hdel Tablename Originaltext 1
  while %i <= %h { 
    hadd Tablename Newtext 2
    inc %i 
  } 
}


Perhaps /hsave and /hload may well be used in this case...


Yes and no, it's the basic routine, but I want to change the item name only and keep the same data.

Actually I'm trimming the ident off the name!ident. When I manually look up an item, I can't remember their ident, but I have their name.


I registered; you should too.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
You can't rename items or table names. There has been a suggestion for /hrename as far as table names go but I doubt there would be one for items because it doesn't make sense given how hash tables work (a unique name has a unique place in the list-- if the name is changed it has to be deleted and moved no matter what- you can't just change the symbol name). Renaming is essentially equivalent to creating a new item and deleting the old one anyway (that's what mIRC would do internally), and if mIRC had a concept of ByRef's then this would essentially be a non-intensive trivial process.

On a sidenote, you don't need table renaming for the problem you're describing-- $hfind can do lookups on keys, so you can search for key name!*. In any case, renaming wouldn't help anyway-- you're going to rename the entire list every time you can't remember an ident? Begs the question of why you'd store the ident in the first place.

Keys should always be known and be as consistent as possible. If your key is changing often, you should consider calling it data and figuring out a better key name for what you're storing. Rehashing a key and inserting it back into the hash table is the most expensive part of how hash tables work, so it's not something you should take lightly.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Link Copied to Clipboard