aboutsummaryrefslogtreecommitdiff
path: root/src/common/ht.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/ht.h')
-rw-r--r--src/common/ht.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/ht.h b/src/common/ht.h
index 095bca356b..61792cb8b4 100644
--- a/src/common/ht.h
+++ b/src/common/ht.h
@@ -65,6 +65,7 @@ ht_improve_hash(unsigned h)
return h;
}
+#if 0
/** Basic string hash function, from Java standard String.hashCode(). */
static INLINE unsigned
ht_string_hash(const char *s)
@@ -77,6 +78,21 @@ ht_string_hash(const char *s)
}
return h;
}
+#endif
+
+/** Basic string hash function, from Python's str.__hash__() */
+static INLINE unsigned
+ht_string_hash(const char *s)
+{
+ unsigned h;
+ const unsigned char *cp = (const unsigned char *)s;
+ h = *cp << 7;
+ while (*cp) {
+ h = (1000003*h) ^ *cp++;
+ }
+ h ^= (cp-(const unsigned char*)s);
+ return h;
+}
#define _HT_SET_HASH(elm, field, hashfn) \
(elm)->field.hte_hash = hashfn(elm)