|
Joined: Jan 2006
Posts: 5
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2006
Posts: 5 |
I was wondering if anyone could provide me with a command Hash Table script that will go through a Hash Table and delete all the Items that don't have no Data in them.
Example
alias NoData { etc }
|
|
|
|
Joined: Jul 2006
Posts: 4,193
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,193 |
alias del_nodata {
var %a = $$hget($$1,0).item
while (%a) {
if ($hget($1,%a) == $null) hdel $1 $hget($1,%a).item
dec %a
}
} Use /del_nodata htable_name
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2006
Posts: 5
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2006
Posts: 5 |
Thank you for your response. I tested it out but it deletes everything in the Hash Table with or without data in the Item of the Hash Table.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
change if ($hget($1,%a) == $null) hdel $1 $hget($1,%a).item to if ($hget($1,%a).data == $null) hdel $1 $hget($1,%a).item
|
|
|
|
Joined: Jul 2006
Posts: 4,193
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,193 |
Yeah, forgot one thing, the RusselB's code will work but that's not what should be used, here is the correction : if ($hget($1,$hget($1,%a).item) == $null) hdel $1 $hget($1,%a).item
Last edited by Wims; 18/06/09 04:26 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2006
Posts: 5
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Jan 2006
Posts: 5 |
Thanks guys, works perfectly now, appreciate it.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Would you kindly explain why your code should be used and mine shouldn't, when they both work, and yours actually requires mIRC to do two $hget's as mine only requires one?
|
|
|
|
Joined: Jul 2006
Posts: 4,193
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,193 |
I said "should" because the help file state this : You can also reference the Nth data value directly with $hget().data.
Note: This method is provided as a convenience, it is not an efficient way to use the hash table. I also gave this solution because that what I wanted to use first
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
I think the "efficient" way the helpfile talks about is accessing item's data with $hget(table,itemname) instead of $hget(table,itemN).data As the first method is no option here RusselB's method is fine - and, according to a rough bench, slightly faster (~ 25%)
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Maybe Khaled will read this topic and feel like clarifying that section of the help file.
It makes no sense to me, that a method that shows ~25% speed increase could be called "inefficient".
|
|
|
|
Joined: Apr 2003
Posts: 342
Fjord artisan
|
Fjord artisan
Joined: Apr 2003
Posts: 342 |
Hmmm... RussleB's code looks the hash table up one; wims's twice. Doing two table look ups will take longer than when one is needed... isn't that obvious...
Beware of MeStinkBAD! He knows more than he actually does!
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,156 |
I was wondering if anyone could provide me with a command Hash Table script that will go through a Hash Table and delete all the Items that don't have Data in them.
if ($hget($1,$hget($1,%a).item) == $null) hdel $1 $hget($1,%a).item
This will look for an ITEM that is null, not data. Russel's code is what was asked for. Am I wrong? As for the efficiency, I would speculate that using the true item name is more efficient than having mIRC go to the Nth item and display the data.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
$hget(table,N).item = name of Nth item $hget(table,<item>) = data of the item with name <item> thus: $hget(table,$hget(table,N).item) == $hget(table,N).data = data of Nth item
Wims' code works - he only avoided using the .data property (due to a a misinterpretation of the abovementioned phrase in the helpfile, I suppose).
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,156 |
lol, i didnt even see the first $hget. I better get some sleep.
|
|
|
|
Joined: Jul 2006
Posts: 4,193
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,193 |
Hmmm... RussleB's code looks the hash table up one; wims's twice. Doing two table look ups will take longer than when one is needed... isn't that obvious... It is, but as it is to respect what the mirc help file says, especially on a official forum. I've not misinterpret the statement, I've just use it.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Just to clarify, the help file means that $hget(table,N).data is not an efficient way of getting the item's data compared to $hget(table,item). That's because the former has to go through the items one by one internally whereas the latter jumps directly to "item" (this is due to how hash tables work - see wikipedia's entry on this for more). $hget(table,N).item is the same as $hget().data in terms of efficiency: it too has to go through the items. So using $hget(table,$hget(table,N).item) is no more efficient than $hget(table,N).data - in fact it is slightly slower due to the extra $hget(). As implied before in this thread, you do need to go through items without knowing their names, so the fast way of accessing the hash table ($hget(table,item)) is not applicable here: one has to use either .item or .data.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
|