Home AMX User Forum AMX Technical Discussion

Hashing Functions

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'.

Comments

  • jweatherjweather Posts: 320
    No... I can't think of any advantage hashing would provide over simple string comparisons. The thread you're referencing just talks about breaking up a large SELECT ACTIVE by string length, not for performance but to keep it from getting too large.
  • jweatherjweather Posts: 320
    Following on to my previous post, I can't think of any advantage for typical RS-232 parsing scenarios with less than, say, 100 strings to match. Even if it works slightly faster, the amount of time to implement it and the time to maintain it would outweigh the speed advantage in my mind, especially since most devices are sending out a message at most 10-15 times per second.

    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.
  • PhreaKPhreaK Posts: 966
    jweather wrote: »
    No... I can't think of any advantage hashing would provide over simple string comparisons.

    I was thinking that would be the case. Twas just curios to see if others had experimented with them in the past.
  • Spire_JeffSpire_Jeff Posts: 1,917
    I did the basic hash of sorting on first letter, then second letter in this thread: http://amxforums.com/showthread.php?t=5307

    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
Sign In or Register to comment.