|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
If I was to add to a hash table like thos
hadd -m image.1_NUMBER_0_PIXEL_2_0 2_0 $false hadd -m image.1_NUMBER_0_PIXEL_3_0 3_0 $true hadd -m image.1_NUMBER_0_PIXEL_1_1 1_1 $false hadd -m image.1_NUMBER_0_PIXEL_4_1 4_1 $false
How can I then get the total number of hash entries that match table: image.1_NUMBER_0_* ..that are set to $true?
in the above case, it should be 1
Last edited by pouncer; 11/05/07 12:28 AM.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
You'd have to do a loop with $hfind and $hget. Use $hfind with wildcards to find the item names and loop through from 1 to N and $hget the result of each to see if it's $true.
var %cnt = 1, %total = $hfind(table,image.1_NUMBER_0_*,0,w)
while (%cnt <= %total) {
if ($hget(table,$hfind(table,image.1_NUMBER_0_*,%cnt,w)) == $true) {
inc %true
}
inc %cnt
}
echo -a True: %true
Just change what you need to (table name, etc). Below is a more verbose version that should make it easy to see how it works. I wouldn't suggest using the code below. It's just here to help explain how it works.
var %cnt = 1
var %item.search = image.1_NUMBER_0_*
var %total = $hfind(table,%item.search,0,w)
while (%cnt <= %total) {
var %item.name = $hfind(table,%item.search,%cnt,w)
if ($hget(table,%item.name) == $true) {
inc %true
}
inc %cnt
}
echo -a True: %true
Last edited by Riamus2; 11/05/07 01:08 AM.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
Thanks mate. what about something like this:
hadd -m @Number.1 0 6 hadd -m @Number.1 1 3 hadd -m @Number.1 2 4 hadd -m @Number.1 3 4 hadd -m @Number.1 4 20 hadd -m @Number.1 5 5 hadd -m @Number.1 6 7 hadd -m @Number.1 7 5 hadd -m @Number.1 8 5 hadd -m @Number.1 9 4
I want to pick out the table name/data which contains the hightest number which is @Number.1 4
Is there a way to grab this info without using loops?
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Save it to a file or to a custom window with line numbers and use /filter, then use $hget on the line number to get the right item. See this thread (post by DaveC) for more information on sorting hash tables.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Without using a loop, save the hash table to a file, then use /filter on the file.
Personally, I'd prefer to use a loop for something like this, as the results would be almost instantaneous, especially with a table that only has 10 items in it
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
Ahhh, cheers bud.
I'll give it a read!
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
hey riamus i got a small problem, this time i got 2 tables:
hadd -m @Number.1 0 6 hadd -m @Number.1 1 3 hadd -m @Number.1 2 4 hadd -m @Number.1 3 4 hadd -m @Number.1 4 20 hadd -m @Number.1 5 5 hadd -m @Number.1 6 7 hadd -m @Number.1 7 5 hadd -m @Number.1 8 5 hadd -m @Number.1 9 4
hadd -m @Number.2 0 3 hadd -m @Number.2 1 16 hadd -m @Number.2 2 7 hadd -m @Number.2 3 6 hadd -m @Number.2 4 3 hadd -m @Number.2 5 6 hadd -m @Number.2 6 6 hadd -m @Number.2 7 5 hadd -m @Number.2 8 2 hadd -m @Number.2 9 5
again for @Number.1 it should return '4' as it has highest value of 20.
for @Number.2 it should return 1 as it has highest value 16.
i couldnt get this working with tha filter thing, any ideas guys?
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Don't forget with the filter method that you need to sort based on the second "word" in your data, not the first. And you want to sort with a numeric sort.
Display the code you have.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Oct 2005
Posts: 827
Hoopy frood
|
OP
Hoopy frood
Joined: Oct 2005
Posts: 827 |
alias ts {
hfree -w *Number*
hadd -m @Number.1 0 6
hadd -m @Number.1 1 3
hadd -m @Number.1 2 4
hadd -m @Number.1 3 4
hadd -m @Number.1 4 20
hadd -m @Number.1 5 5
hadd -m @Number.1 6 7
hadd -m @Number.1 7 5
hadd -m @Number.1 8 5
hadd -m @Number.1 9 4
hadd -m @Number.2 0 3
hadd -m @Number.2 1 16
hadd -m @Number.2 2 7
hadd -m @Number.2 3 6
hadd -m @Number.2 4 3
hadd -m @Number.2 5 6
hadd -m @Number.2 6 6
hadd -m @Number.2 7 5
hadd -m @Number.2 8 2
hadd -m @Number.2 9 5
hsave -no @Number.1 tempfile.txt
hsave -no @Number.2 tempfile.txt
filter -ffcteun 1 32 tempfile.txt tempfile.txt
}
the tempfile.txt reads like this:
9 16
10 7
1 6
3 6
4 6
5 5
7 5
2 3
8 3
6 2
:s All I'm trying to do is capture the number '4' and '1' as they have the highest values in @number.1 and @number.2 respectively
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
You'll have to save each hash table and filter the saved file, one at a time or use different names for the input &/or output of the /filter command, otherwise you're going to get incorrect results.
|
|
|
|
Joined: Jun 2006
Posts: 508
Fjord artisan
|
Fjord artisan
Joined: Jun 2006
Posts: 508 |
If there's not too many entries in the tables, it may be quicker/easier to loop the table items. ; /gethigh <Table> (/gethigh @Number.1)
alias gethigh {
var %i = 1,%a = 0,%b
while $hget($$1,%i).data {
if $v1 > %a { var %a = $v1,%b = %i }
inc %i
}
echo -a $1 $hget($1,%b).item == %a
}
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Please ensure that you read all of the posts before posting, as the OP stated in their second post Is there a way to grab this info without using loops?
|
|
|
|
|