mIRC Home    About    Download    Register    News    Help

Print Thread
#213110 18/06/09 02:52 PM
Joined: Jan 2006
Posts: 5
B
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
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,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Code:
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
B
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
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
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
change
Code:
if ($hget($1,%a) == $null) hdel $1 $hget($1,%a).item
to
Code:
if ($hget($1,%a).data == $null) hdel $1 $hget($1,%a).item



Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Yeah, forgot one thing, the RusselB's code will work but that's not what should be used, here is the correction :
Code:
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
B
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 5
Thanks guys, works perfectly now, appreciate it.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
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,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
I said "should" because the help file state this :
Originally Posted By: /help $hget
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
H
Hoopy frood
Offline
Hoopy frood
H
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%) smile

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
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
M
Fjord artisan
Offline
Fjord artisan
M
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
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Originally Posted By: Bootyman
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.


Originally Posted By: wims

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
H
Hoopy frood
Offline
Hoopy frood
H
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
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
lol, i didnt even see the first $hget. I better get some sleep.

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Quote:
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
Q
Hoopy frood
Offline
Hoopy frood
Q
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

Link Copied to Clipboard