]> granicus.if.org Git - pgbouncer/commitdiff
<usual/lookup3.h>
authorMarko Kreen <markokr@gmail.com>
Mon, 11 Jan 2010 05:50:20 +0000 (07:50 +0200)
committerMarko Kreen <markokr@gmail.com>
Tue, 4 May 2010 11:30:49 +0000 (14:30 +0300)
Makefile
include/bouncer.h
include/hash.h [deleted file]
src/hash.c [deleted file]

index 07a2675201402b6356d71a09dc0dd0d82ff0bee7..4c69b1a5c07bb3fc0ebb13bc6c13f60c69623851 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,10 +2,10 @@
 # sources
 SRCS = client.c loader.c objects.c pooler.c proto.c sbuf.c server.c util.c \
        admin.c stats.c takeover.c md5.c janitor.c pktbuf.c system.c main.c \
-       varcache.c hash.c slab.c
+       varcache.c slab.c
 HDRS = client.h loader.h objects.h pooler.h proto.h sbuf.h server.h util.h \
        admin.h stats.h takeover.h md5.h janitor.h pktbuf.h system.h bouncer.h \
-       mbuf.h varcache.h hash.h slab.h iobuf.h
+       mbuf.h varcache.h slab.h iobuf.h
 
 # data & dirs to include in tgz
 DOCS = doc/overview.txt doc/usage.txt doc/config.txt doc/todo.txt
index f5becd4ac868e607f33a7e2c6077b70dfa563754..2bc431b8c26c95b6e72ff4d3401c9c77bc6cddea 100644 (file)
@@ -28,6 +28,7 @@
 #include <usual/string.h>
 #include <usual/logging.h>
 #include <usual/aatree.h>
+#include <usual/lookup3.h>
 
 #include <event.h>
 
@@ -75,7 +76,6 @@ typedef struct PktHdr PktHdr;
 
 extern int cf_sbuf_len;
 
-#include "hash.h"
 #include "util.h"
 #include "mbuf.h"
 #include "iobuf.h"
diff --git a/include/hash.h b/include/hash.h
deleted file mode 100644 (file)
index a676f87..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/* The contents of this file are public domain. */
-
-uint32_t lookup3_hash(const void *data, size_t len);
-
-uint32_t hash32(uint32_t v);
-
-static inline uint32_t ptr_hash32(const void *ptr)
-{
-       return hash32((uint32_t)(long)ptr);
-}
-
diff --git a/src/hash.c b/src/hash.c
deleted file mode 100644 (file)
index ff05596..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * The contents of this file are public domain.
- *
- * Based on: lookup3.c, by Bob Jenkins, May 2006, Public Domain.
- */
-
-#include "system.h"
-#include "hash.h"
-
-/*
- * A simple version of Bob Jenkins' lookup3.c hash.
- *
- * It is supposed to give same results as hashlittle() on little-endian
- * and hashbig() on big-endian machines.
- *
- * Speed seems comparable to Jenkins' optimized version (~ -10%).
- * Actual difference varies as it depends on cpu/compiler/libc details.
- */
-
-/* rotate uint32 */
-#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
-
-/* mix 3 32-bit values reversibly */
-#define mix(a, b, c) do { \
-       a -= c;  a ^= rot(c, 4);  c += b; \
-       b -= a;  b ^= rot(a, 6);  a += c; \
-       c -= b;  c ^= rot(b, 8);  b += a; \
-       a -= c;  a ^= rot(c,16);  c += b; \
-       b -= a;  b ^= rot(a,19);  a += c; \
-       c -= b;  c ^= rot(b, 4);  b += a; \
-} while (0)
-
-/* final mixing of 3 32-bit values (a,b,c) into c */
-#define final(a, b, c) do { \
-       c ^= b; c -= rot(b,14); \
-       a ^= c; a -= rot(c,11); \
-       b ^= a; b -= rot(a,25); \
-       c ^= b; c -= rot(b,16); \
-       a ^= c; a -= rot(c, 4); \
-       b ^= a; b -= rot(a,14); \
-       c ^= b; c -= rot(b,24); \
-} while (0)
-
-/*
- * GCC does not know how to optimize short variable-length copies.
- * Its faster to do dumb inlined copy than call out to libc.
- */
-static inline void simple_memcpy(void *dst_, const void *src_, size_t len)
-{
-       const uint8_t *src = src_;
-       uint8_t *dst = dst_;
-       while (len--)
-               *dst++ = *src++;
-}
-
-/* short version - let compiler worry about memory access */
-uint32_t lookup3_hash(const void *data, size_t len)
-{
-       uint32_t a, b, c;
-       uint32_t buf[3];
-       const uint8_t *p = data;
-
-       a = b = c = 0xdeadbeef + len;
-       if (len == 0)
-               goto done;
-
-       while (len > 12) {
-               memcpy(buf, p, 12);
-               a += buf[0];
-               b += buf[1];
-               c += buf[2];
-               mix(a, b, c);
-               p += 12;
-               len -= 12;
-       }
-
-       buf[0] = buf[1] = buf[2] = 0;
-       simple_memcpy(buf, p, len);
-       a += buf[0];
-       b += buf[1];
-       c += buf[2];
-       final(a, b, c);
-done:
-       return c;
-}
-
-
-/*
- * Reversible integer hash function by Thomas Wang.
- */
-
-uint32_t hash32(uint32_t v)
-{
-       v = ~v + (v << 15);
-       v = v ^ (v >> 12);
-       v = v + (v << 2);
-       v = v ^ (v >> 4);
-       v = v * 2057;
-       v = v ^ (v >> 16);
-       return v;
-}
-