shithub: mc

Download patch

ref: 36cfe833d4df23b2e0da38942c8d51de0bd72f6d
parent: 10e157391eb2e75c3d38620529b356b302c4a2e5
author: Ori Bernstein <[email protected]>
date: Tue Jan 3 14:41:32 EST 2012

Add hashing util funcs

--- a/parse/htab.c
+++ b/parse/htab.c
@@ -134,3 +134,26 @@
             k[j++] = ht->keys[i];
     return k;
 }
+
+ulong strhash(void *_s)
+{
+    char *s;
+    ulong h;
+    ulong g;
+
+    s = _s;
+    while (s && *s) {
+        h = ((h << 4) + *s++);
+
+        if ((g = (h & 0xF0000000)))
+            h ^= (g >> 24);
+
+        h &= ~g;
+    }
+    return h;
+}
+
+int streq(void *a, void *b)
+{
+    return !strcmp(a, b);
+}
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -233,7 +233,7 @@
 void **htkeys(Htab *ht);
 /* useful key types */
 ulong strhash(void *str);
-ulong streq(void *s1, void *s2);
+int streq(void *s1, void *s2);
 
 /* util functions */
 void *zalloc(size_t size);