mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
Hey, I'm Having a little trouble finding the syntax to getting a call to $hget to return a number for an item name, example:

hash table: test contains 4 items:

me -
you -
him -
her -

i am trying to find $hget(test,you) (OR whatever the right way is) to return 2, as you is the second item in the table, i'm might be wrong, but i was pretty sure there was a way to do this, without looping through it?

Joined: Dec 2002
Posts: 77
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2002
Posts: 77
It's not necessarily the 2nd item in the table as hash tables don't store items in the order you add them, so what you're requesting isn't relevant.

Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
i think what they are asking is a way to find what position "you" has in the hash table wether it be 1 2 3 or 4 just return the position of the specified item

Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
i am not that familiar with hash tables but perhaps if you used the .data property ?

$hget(test,you).data


Joined: Dec 2002
Posts: 77
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2002
Posts: 77
I think the only way to obtain an item number is to iterate through the hash table. I don't see any possible usefulness of knowing the current item number though.

Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
Yeah, i was trying to find WHAT Possision "you" would be in the table WITHOUT looping through it, but it seems there isnt a way, so for now i have it using a loop, untill it supposrt that function i guess :P

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Hash tables aren't meant to be used as you are trying to use them; they are a very fast way to access the item/data directly rather than having to loop through lines/items/entries. If you need that kind of sequential storage, then sequence your item names:

hadd test n1 me
hadd test n2 you
hadd test n3 him
hadd test n4 her

$hget(test, $+(n,$1)) where $1 is the value you wish to "find"


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
Well you see, i made a dialog, and does certain things, contains information, pertaining to hash tables, and i made the option to "Find Text", so it searches all hash tables if thats what they want, and i was looking for a faster way to get the possision of a certain item in a hash table then looping through it.....

Joined: Dec 2002
Posts: 774
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 774
/help $hfind
look at .data property


Code:
//if ( khaled isgod ) echo yes | else echo no
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
i dont think you guys are understanding me, i am not trying to find data for an item, if i have ten items in my hash table, and if i type //echo -a $hget(table,8) that will give me the NAME of the 8th item, I WAS ASKING If there was a way to type like: //echo -a $hget(table,item8).pos or whatever the heck you wanna call it, and it would return 8, get it now? has NOTHING to do with data, but positions of items!

Joined: Dec 2002
Posts: 77
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2002
Posts: 77
You'd have to iterate through the hash table to get the 'position', though next time an item is added/deleted, the position for the item you originally looked for will most likely change.

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
And you are not understanding US. We have REPEATEDLY told you that the so-called "position" that you're looking for will change as you add or remove items ... or it might even change the next time you load the hash table. In a hash table, $hget(htable, N) does NOT stay the same forever...it will remain the same until the table changes and might even remain the same through several changes. Position as you define it is a meaningless expression. The method is there ONLY so you can sequentially iterate through a hash table, but it is NOT meant to be a consistent item value for each data value assigned, positionally speaking, not the way you're thinking of it. That is WHY there is no .property or $identifier or method to get the position number "8" out of 10 hash table entries.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
So be it if the item number changes, for the time it checks to see what position it is, it will not change untill the position isnt needed anymore, for like i said above, it was for a simple search function, and when the user clicks the button, i needed to know the position of a certain item, for that ONE Instatnce, not for an hour, or minute, but for a second, at which time it would not matter if the position changed or not, as the next time we would need it, we would FIND OUT what it is AGAIN, As we need to know, otherwize it doesnt matter what the position is, It Can Change All it Wants between then.
So As There Isnt An Identifer To Achive This, Which BTW I Think There Should Be, As It Can Come In Handy For Some Things, I Had to Do It With A Loop Instead, Which Is Fine, As Stated Above.... I Know ALL About The Hash Tables And Their Commands, But I Wasnt Sure About the Position Identifer, Was Sure I Seen It a While Back, but Like I Said IN My First Post, I Could Be Wrong, if I Wanted To Get Data, Then thats what My Question Would Have Been, lol, Sorry For Any Confusion That May Have Come Of This, But I Knew What I Was Asking, And Was Getting Answer To Something Totaly Different, lol, So anyway, hope Wthis Clears It Up A Little!


Link Copied to Clipboard