mIRC Homepage
Posted By: bebegood hash tables, top bot numbers - 18/01/10 12:18 PM
Feature:
adds command to get top/bot numbers in data, from hash table, example:

'''''hash'''''''

test1
1
test2
2
test3
3
test4
4

''''''''''''''''''''

$hget(hash,1).topnumber > return item Test4
$hget(hash,1).botnumber > return item Test1

$hget(hash,2).botnumber > return Item Test3

example...

Reasoning:
if in hash table 5000-6000 items, to sort this, need some time.. (long :p)
and can not get it life (now)
need always sort...

if you add it, that will be very very good, thx.


Sry for my bad eng.
Posted By: Riamus2 Re: hash tables, top bot numbers - 18/01/10 04:38 PM
If you're trying to sort hash table data, it can be done by saving the table and using /filter.

I don't have mIRC in front of me to get an exact example for you, but the basic idea is:

/hsave the table to a temp file
/filter the temp file using the switch (check help for the right one) that saves the original line number. Filter in decending order. Then, because you have the original line numbers, you'll end up with something like:

Original:
23
465
214
12
6

New:
5 6
4 12
1 23
3 214
2 465

Now, you can pull the right information from the hash table using that line number - $hget(hashtable,line#). You can get the name and/or data that way allowing you to display the top values. The same method can be done to see the lowest values if you change the list to ascending order in filter.

I'm sure someone can give an actual script example for this. I just don't have it in front of me and I don't use /filter often enough to remember all of the switches.

As far as a feature, I wouldn't mind having a sort function for hash tables even though they are by definition unsorted. But it's at least a very easy thing to sort using this method.
Posted By: Wims Re: hash tables, top bot numbers - 18/01/10 05:20 PM
Even if your method is doable, hsave isn't saving the table in a text file format with just one line = one item/data/both
Posted By: Riamus2 Re: hash tables, top bot numbers - 18/01/10 05:24 PM
You save it just with data (no names). Forgot to mention that. /help /hsave to get that switch.

Because you're including line numbers (which correspond to the item number in the table), you don't need to save the name of each item, just the data.

It does work really well and I use it in a few scripts. I tried searching for it on the forums, but didn't have luck finding it. It's been posted here numerous times in the past.

Basic idea (fill in missing switches):

Code:
alias filterhash {
  hsave tablename table.tmp   ** Include switch to save data only
  filter -ff table.tmp table.tmp   ** Include switches to save in decending order and to include original line numbers
  echo -a Top: $hget(tablename,$gettok($read(table.tmp,1),1,32)).item
}


That's a basic idea of how it works. You can, of course, include the value in the echo instead of just the item. I just did that to give the barebones view of how it works. If anyone has the help file (or just knows the switches), maybe you can post the "finished" version of this that includes the correct switches. /filter should have -ffeu and something for including line numbers, I believe.
Posted By: s00p Re: hash tables, top bot numbers - 19/01/10 01:10 AM
That will work work just fine in this case. Your comment is quite useless, Wims.
Posted By: Wims Re: hash tables, top bot numbers - 19/01/10 02:16 AM
Ok thank you.
Otherwise, before he says to only backup the data (-n), it would not work
Posted By: bebegood Re: hash tables, top bot numbers - 25/02/10 01:09 PM
ok
© mIRC Discussion Forums