Hashing Functions
PhreaK
Posts: 966
Is anyone using hashing in their string processing? I know a_riot42 has mentioned their use in the past (http://www.amxforums.com/showpost.php?p=34663&postcount=12) but just wondering if anyone has found a function that plays nice with the NI processors. I'm currently tossing up between using an FNV hash or an implimentation of Paul Hsieh's 'super fast hash'.
0
Comments
If you really had a boatload of possible strings to match, I would start by breaking them up by length. It's already computed for you, it's fairly easy to keep the strings sorted by length, and it would reduce the number of string comparisons needed as long as the responses are different lengths.
If the strings were distributed across the alphabet, you could also break them up by the first letter -- essentially a very simple hash.
If you really feel the need to hash the strings, you can do something simple like adding the character values of the first and third characters and taking the MOD 13 or something, and switch on that. Any kind of general-purpose hashing algorithm is likely to be complete overkill, and the extra cycles spent in computing it reduce any speed benefit you might see.
But if you're bored, by all means implement FNV -- it'll be educational, just not very useful.
I was thinking that would be the case. Twas just curios to see if others had experimented with them in the past.
Obviously the sample set is rather small, but it seemed that doing a list of switch case statements was faster. I think it just comes down to fewer operations being performed.
Jeff