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
diff --git a/lib/hash.c b/lib/hash.c
index 672327e..6db79ea 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -101,6 +101,17 @@
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. */