… | |
… | |
511 | // use FNV-1a hash (http://isthe.com/chongo/tech/comp/fnv/) |
511 | // use FNV-1a hash (http://isthe.com/chongo/tech/comp/fnv/) |
512 | // it is about twice as fast as the one-at-a-time one, |
512 | // it is about twice as fast as the one-at-a-time one, |
513 | // with good distribution. |
513 | // with good distribution. |
514 | // FNV-1a is faster on many cpus because the multiplication |
514 | // FNV-1a is faster on many cpus because the multiplication |
515 | // runs concurrently with the looping logic. |
515 | // runs concurrently with the looping logic. |
|
|
516 | // we modify the hash a bit to improve its distribution |
516 | uint32_t hash = STRHSH_NULL; |
517 | uint32_t hash = STRHSH_NULL; |
517 | |
518 | |
518 | while (*s) |
519 | while (*s) |
519 | hash = (hash ^ *s++) * 16777619U; |
520 | hash = (hash ^ *s++) * 16777619U; |
520 | |
521 | |
521 | return hash; |
522 | return hash ^ (hash >> 16); |
522 | } |
523 | } |
523 | |
524 | |
524 | static inline uint32_t |
525 | static inline uint32_t |
525 | memhsh (const char *s, size_t len) |
526 | memhsh (const char *s, size_t len) |
526 | { |
527 | { |