mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2010
Posts: 10
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2010
Posts: 10
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.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.

Last edited by Riamus2; 18/01/10 05:32 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
That will work work just fine in this case. Your comment is quite useless, Wims.

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Ok thank you.
Otherwise, before he says to only backup the data (-n), it would not work


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2010
Posts: 10
B
Pikka bird
OP Offline
Pikka bird
B
Joined: Jan 2010
Posts: 10
ok


Link Copied to Clipboard