diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2010-08-27 14:11:14 -0700 |
---|---|---|
committer | Paul Jakma <paul@quagga.net> | 2011-03-21 13:30:54 +0000 |
commit | 6392aa83c4f895ebbd23817c68d9b0da0de2e0f8 (patch) | |
tree | 535c89a194ec7fd3b9f4a6e33ceab10579e62329 /lib/hash.c | |
parent | 25ff1e88bb5f1b0a16a364d7206db3ebdc5ecf52 (diff) | |
download | quagga-6392aa83c4f895ebbd23817c68d9b0da0de2e0f8.tar.bz2 quagga-6392aa83c4f895ebbd23817c68d9b0da0de2e0f8.tar.xz |
lib: Better hashing of string values using Bernstein hash
* hash.{h,c}: (string_hash_make) Hash optimised for strings, current
implementation using Bernstein hash, which offers a good compromise
between distribution and performance.
* distribute.c: (distribute_hash_make) use previous instead of additive
string hash.
* if_rmap.c: (if_rmap_hash_make) ditto
Diffstat (limited to 'lib/hash.c')
-rw-r--r-- | lib/hash.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -101,6 +101,17 @@ hash_lookup (struct hash *hash, void *data) return hash_get (hash, data, NULL); } +/* Simple Bernstein hash which is simple and fast for common case */ +unsigned int string_hash_make (const char *str) +{ + unsigned int hash = 0; + + while (*str) + hash = (hash * 33) ^ (unsigned int) *str++; + + return hash; +} + /* This function release registered value from specified hash. When release is successfully finished, return the data pointer in the hash backet. */ |