mIRC Home    About    Download    Register    News    Help

Print Thread
Hash Table Script Help #213110 18/06/09 02:52 PM
Joined: Jan 2006
Posts: 5
B
Bootyman Offline OP
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
}

Re: Hash Table Script Help [Re: Bootyman] #213112 18/06/09 03:19 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
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



Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Hash Table Script Help [Re: Wims] #213117 18/06/09 04:01 PM
Joined: Jan 2006
Posts: 5
B
Bootyman Offline OP
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.

Re: Hash Table Script Help [Re: Bootyman] #213120 18/06/09 04:16 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
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



Re: Hash Table Script Help [Re: Bootyman] #213123 18/06/09 04:25 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
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.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Hash Table Script Help [Re: Wims] #213124 18/06/09 04:35 PM
Joined: Jan 2006
Posts: 5
B
Bootyman Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 5
Thanks guys, works perfectly now, appreciate it.

Re: Hash Table Script Help [Re: Wims] #213139 18/06/09 11:14 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
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?

Re: Hash Table Script Help [Re: RusselB] #213140 18/06/09 11:26 PM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
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


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Hash Table Script Help [Re: Wims] #213143 19/06/09 01:05 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
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

Re: Hash Table Script Help [Re: Horstl] #213144 19/06/09 01:31 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
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".

Re: Hash Table Script Help [Re: RusselB] #213602 02/07/09 05:45 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
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!
Re: Hash Table Script Help [Re: Bootyman] #213605 02/07/09 07:49 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
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.

Re: Hash Table Script Help [Re: DJ_Sol] #213606 02/07/09 08:01 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
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).


Re: Hash Table Script Help [Re: Horstl] #213608 02/07/09 09:49 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
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.

Re: Hash Table Script Help [Re: MeStinkBAD] #213609 02/07/09 10:10 AM
Joined: Jul 2006
Posts: 3,702
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,702
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Hash Table Script Help [Re: Wims] #213611 02/07/09 12:33 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
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