]> granicus.if.org Git - pgbouncer/commitdiff
int/ptr hash function
authorMarko Kreen <markokr@gmail.com>
Thu, 6 Dec 2007 09:18:15 +0000 (09:18 +0000)
committerMarko Kreen <markokr@gmail.com>
Thu, 6 Dec 2007 09:18:15 +0000 (09:18 +0000)
include/hash.h
src/hash.c

index 3a82476ea9ac33e1ce7a96bdaab44ee17f162a8c..fb2e67f826d2a96a8311b49781322410fc542f43 100644 (file)
@@ -1,3 +1,10 @@
 
 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);
+}
+
index 80179a8464ec175bf0136a3f862a4f709c4c7d3e..5c9a73639ad098c296c0be562c34573189f3e083 100644 (file)
@@ -16,6 +16,9 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "system.h"
+#include "hash.h"
+
 /*
  * A simple version of Bob Jenkins' lookup3.c hash.
  *
@@ -26,9 +29,6 @@
  * Actual difference varies as it depends on cpu/compiler/libc details.
  */
 
-#include "system.h"
-#include "hash.h"
-
 /* rotate uint32 */
 #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
 
@@ -84,3 +84,19 @@ 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;
+}
+