]> Zhao Yanbai Git Server - minix.git/commitdiff
<minix/hash.h>
authorBen Gras <ben@minix3.org>
Fri, 15 Oct 2010 11:25:40 +0000 (11:25 +0000)
committerBen Gras <ben@minix3.org>
Fri, 15 Oct 2010 11:25:40 +0000 (11:25 +0000)
include/Makefile
include/minix/hash.h [new file with mode: 0644]

index 6624401b40f18f76a520a24a09af09d7fad462eb..a39997e17ed4dff873859b61062d2726bc4aebae 100644 (file)
@@ -29,7 +29,7 @@ INCS+=        minix/a.out.h minix/bitmap.h minix/callnr.h minix/cdrom.h \
        minix/sysutil.h minix/timers.h minix/tty.h minix/type.h minix/types.h \
        minix/u64.h minix/vfsif.h minix/vm.h minix/vtreefs.h minix/gcov.h  \
        minix/compiler.h minix/compiler-ack.h minix/sha2.h minix/sha1.h minix/md5.h \
-       minix/audio_fw.h
+       minix/audio_fw.h minix/hash.h
 INCS+= net/hton.h net/if.h net/ioctl.h net/netlib.h
 INCS+= net/gen/arp_io.h net/gen/dhcp.h net/gen/ether.h \
        net/gen/eth_hdr.h net/gen/eth_io.h net/gen/icmp.h \
diff --git a/include/minix/hash.h b/include/minix/hash.h
new file mode 100644 (file)
index 0000000..b4aab01
--- /dev/null
@@ -0,0 +1,49 @@
+
+#ifndef _MINIX_HASH_H
+#define _MINIX_HASH_H 1
+
+#include <stdint.h>
+
+/* This code is taken from:
+ * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
+ * (macro names modified)
+ */
+
+#define hash_rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
+
+#define hash_mix(a,b,c) \
+{ \
+  a -= c;  a ^= hash_rot(c, 4);  c += b; \
+  b -= a;  b ^= hash_rot(a, 6);  a += c; \
+  c -= b;  c ^= hash_rot(b, 8);  b += a; \
+  a -= c;  a ^= hash_rot(c,16);  c += b; \
+  b -= a;  b ^= hash_rot(a,19);  a += c; \
+  c -= b;  c ^= hash_rot(b, 4);  b += a; \
+}
+
+#define hash_final(a,b,c) \
+{ \
+  c ^= b; c -= hash_rot(b,14); \
+  a ^= c; a -= hash_rot(c,11); \
+  b ^= a; b -= hash_rot(a,25); \
+  c ^= b; c -= hash_rot(b,16); \
+  a ^= c; a -= hash_rot(c,4);  \
+  b ^= a; b -= hash_rot(a,14); \
+  c ^= b; c -= hash_rot(b,24); \
+}
+
+#define hash_i_64(a, u, v) {                           \
+       u32_t i1 = (a), i2 = ex64lo(u), i3 = ex64hi(u); \
+       hash_mix(i1, i2, i3);                           \
+       hash_final(i1, i2, i3);                         \
+       (v) = i3;                                       \
+}
+
+#define hash_32(n, v) {                                        \
+       u32_t i1 = 0xa5a5a5a5, i2 = 0x12345678, i3 = n; \
+       hash_mix(i1, i2, i3);                           \
+       hash_final(i1, i2, i3);                         \
+       (v) = i3;                                       \
+}
+
+#endif