LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hash table

Hi,

I would like to know how can I do a hash table in order to put and retrieve value using a key.

Thanks,

ToNi.
0 Kudos
Message 1 of 15
(9,944 Views)
Hi

How about using a listbox. the text in the listbox can be retrieved via its index.

Goy
0 Kudos
Message 2 of 15
(9,931 Views)
There are several algorithms available for creating unique hashes for data. Haven't tried any myself, but you can try searching for LabVIEW and Hash. You can also try MD5. I think it can help. Try looking at VI Security, they might have what you need.

___________________
Try to take over the world!
0 Kudos
Message 3 of 15
(9,926 Views)
In doing a couple quick searches it seems as though this topic isn't very popular.  Maybe because the solution is easier then I think?? Smiley Surprised

It seems to me that the only way to get data out of a list of data is using an index number... but I want a string value to return a number. For example if you had a telephone directory, and you could select the persons name, and it would return their phone number.

The logical way to me seems to have the names in a text ring, which acts as the index selection to an array of the values you wish to select from...

The only other way I could think of was to have a case selctor, in which each case returns the value associated with the selected text value. Which seems to me to be a better way to handle it when the selection is happening in a sub-vi... because you can pass a single value, and you don't have to pass in the whole text ring to the sub-vi.

Is there any better way?  The more I think about the case statement option the more it seems as though this is the most plausible solution to a hash table type selection. Although, personally i find case statements ( and stacked sequences ) very hard to read at times. Smiley Indifferent

Message Edited by MJBrehm on 08-21-2006 08:54 AM

0 Kudos
Message 4 of 15
(9,785 Views)

I see the word "hash" through me off balance the last time, so how about this for fixing it - create a 2D array with one column being the name and the other being the telephone number. Index out the first column and use Search 1D Array on it to find your name and then use the index of the result to extract the phone number. This, of course, will only be efficient for arrays which aren't too big. The other option is your suggested method with the ring, which I've also used.


___________________
Try to take over the world!
Message 5 of 15
(9,772 Views)
I constructed a hash table while working on one of the coding challenges that involved finding the 4 most frequently used tags in an html file. 
 
The hash table itself was a large array of clusters.  Each cluster bundled together a count #, the key string, and one or two other elements that seeemed helpful / relevant at the time. 
 
Each time I parsed another tag, I used the text string as a "key" into the hash table.  The string was passed into a standard CRC calculation, either a 16-bit or 32-bit, I don't recall.  I then used the CRC value to create an index into the hash table by keeping only the appropriate # of bits.  There was some additional logic to look for and handle hash value collisions.
 
I toyed a little bit with finding a good size for the hash table.  You basically trade off memory storage space for speed.  As you cram your table more and more full to save memory, you can expect more and more hash value collisions to resolve.  My seat-of-the-pants guesstimate was that somewhere around 10-25% fill didn't produce a significant execution speed slow-down.  Greater than 50% fill was more noticeable.
 
I thought I'd posted it, but I can't find the discussion forum thread about that challenge anymore -- maybe it didn't survive the change over to the new forum software.  I may have it somewhere though, and if I can dig it up I'll post the hash table "action engine."
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 6 of 15
(9,762 Views)
Both good suggestions...

I especially like the cluster idea and the ability to pass extra data along with the key value.

Thanks for the replies!!


I was always under the impression that essentially a hash table was basically just an array with a "key" indexing.... It's been awhile since my computer science classes though.... and everytime they mentioned hash tables... I thought of hash browns, and breakfast.... which usually got me side tracked. Smiley Tongue
0 Kudos
Message 7 of 15
(9,754 Views)
FWIW, I'm not sure the implementation I described would be a "true" hash table in the computer science sense.  It's just what I came up with based on a brief, self-taught foray into the concept of hash-based ordered storage for the sake of efficient future look-ups.
 
It's quite a bit more complicated than tst's suggestion, and would not often be worth the extra effort.  If your program's execution time is dominated by these look-ups, then hashing may well help.  Hashing gives you a more-or-less constant look-up time while the "Search 1D Array" function will have time proportional to array size.  Unless your array size gets into the 1000's or more, it's likely to be speedy enough and a whole lot easier to code / debug.
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 8 of 15
(9,746 Views)
Message 9 of 15
(9,743 Views)
Yea... my issue is definetly far underneath the scope of the hashtable...

But this thread has definetly shed light on the subject with reference to labview.

I wound up just using a string control wired to a case statement. May change it over to a text ring just to avoid someone mistyping and getting the default case by accident. I have a set number of data to lookup ( < 10 ) ... so, advanced searching algorithms are definetly not needed.

Thanks for the replies!... maybe in another year someone will revisit this thread with a problem that is more suited for the hashtable. Smiley Very Happy
0 Kudos
Message 10 of 15
(9,735 Views)