mIRC Home    About    Download    Register    News    Help

Print Thread
#123798 27/06/05 01:17 PM
Joined: Sep 2004
Posts: 12
C
ch1zra Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2004
Posts: 12
just now i'm in need of this, so it came to me as idea for new feature...

maybe a command (or identifier) for sorting hash tables... like with different switches for items and data, and another for alphabetic or numeric, ascending/descending... ?? what do you think of this ?


$me
#123799 27/06/05 01:35 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hash tables aren't meant to have a sorted order, they are unsorted by nature. You probably are better off with an arraylist for that.

However, you can use the easy work around of writing the contents of the hash table to a temp file, and sorting the temp file with /filter, since a file on the other hand can be sorted easily.

For saving a hash table's contents to a file, you could use /hsave -oi which will save it as an ini file, with items being seperated from data by a $chr(61) aka =
However that will transform [ ] in the hash table items to ~ ~ to evade ambiguity with topics in an .INI file.

Therefore an easy and very fast trick (which works even faster than hsave -oi) is to use the file handling commands to write every item and its according data to a file using a while loop.

Then it is simply a matter of issuing filter on the temp file, and voila, you have the contents of your hash table sorted.

/help /filter
/help /fopen
/help while loops
/help variables

Alternatively you can also write to a hidden window and /filter the window, if you don't feel comfortable with the file handling commands.


Gone.
#123800 27/06/05 01:35 PM
Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
Hash tables, by nature, can not be sorted. See the wikipedia page about hash tables for more information.

Edit: apparently I'm a slow writer :tongue: leaving the post here for the link anyway

Last edited by Sat; 27/06/05 01:40 PM.
#123801 30/06/05 04:58 AM
Joined: Dec 2002
Posts: 580
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
You can also use a sort from a hidden window listbox. smile


NaquadaBomb
www.mirc-dll.com
#123802 30/06/05 09:07 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
you dont want to be sorting into a listbox, performance is el crapo!

#123803 30/06/05 10:07 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
No you can't, the sorting algorithm when specifying the s switch is alphabetically, and we want to sort numerically.

//window -s @@ | aline @@ 20 | aline @@ 5 | aline @@ 30

You'd have to start padding all numbers to an arbitrarily long enough length using $base, which will result in a sort from lowest to highest value.

And why would you choose a listbox? It offers no extra functionality in this case over a sorted regular window.

Sorry, no dice.


Gone.

Link Copied to Clipboard