]> git.kaiwu.me - nginx.git/commitdiff
ngx_murmur_hash2()
authorIgor Sysoev <igor@sysoev.ru>
Fri, 15 Apr 2011 10:59:24 +0000 (10:59 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 15 Apr 2011 10:59:24 +0000 (10:59 +0000)
auto/sources
src/core/ngx_core.h
src/core/ngx_murmurhash.c [new file with mode: 0644]
src/core/ngx_murmurhash.h [new file with mode: 0644]

index 3e201cf1f1bc611048e5b0fc370d64461cc67fd2..a2af30252a9764bf5cdd2b3436b6c65f674d8b19 100644 (file)
@@ -22,6 +22,7 @@ CORE_DEPS="src/core/nginx.h \
            src/core/ngx_file.h \
            src/core/ngx_crc.h \
            src/core/ngx_crc32.h \
+           src/core/ngx_murmurhash.h \
            src/core/ngx_md5.h \
            src/core/ngx_sha1.h \
            src/core/ngx_rbtree.h \
@@ -50,6 +51,7 @@ CORE_SRCS="src/core/nginx.c \
            src/core/ngx_inet.c \
            src/core/ngx_file.c \
            src/core/ngx_crc32.c \
+           src/core/ngx_murmurhash.c \
            src/core/ngx_rbtree.c \
            src/core/ngx_radix_tree.c \
            src/core/ngx_slab.c \
index 5939166af19180a293c0ecb4a215f3ca1a2df021..9f17901534190a91ac0e3f07b90dd9c37626bab8 100644 (file)
@@ -58,6 +58,7 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
 #include <ngx_file.h>
 #include <ngx_crc.h>
 #include <ngx_crc32.h>
+#include <ngx_murmurhash.h>
 #if (NGX_PCRE)
 #include <ngx_regex.h>
 #endif
diff --git a/src/core/ngx_murmurhash.c b/src/core/ngx_murmurhash.c
new file mode 100644 (file)
index 0000000..c31e0e0
--- /dev/null
@@ -0,0 +1,50 @@
+
+/*
+ * Copyright (C) Austin Appleby
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+uint32_t
+ngx_murmur_hash2(u_char *data, size_t len)
+{
+    uint32_t  h, k;
+
+    h = 0 ^ len;
+
+    while (len >= 4) {
+        k  = data[0];
+        k |= data[1] << 8;
+        k |= data[2] << 16;
+        k |= data[3] << 24;
+
+        k *= 0x5bd1e995;
+        k ^= k >> 24;
+        k *= 0x5bd1e995;
+
+        h *= 0x5bd1e995;
+        h ^= k;
+
+        data += 4;
+        len -= 4;
+    }
+
+    switch (len) {
+    case 3:
+        h ^= data[2] << 16;
+    case 2:
+        h ^= data[1] << 8;
+    case 1:
+        h ^= data[0];
+        h *= 0x5bd1e995;
+    }
+
+    h ^= h >> 13;
+    h *= 0x5bd1e995;
+    h ^= h >> 15;
+
+    return h;
+}
diff --git a/src/core/ngx_murmurhash.h b/src/core/ngx_murmurhash.h
new file mode 100644 (file)
index 0000000..ae40779
--- /dev/null
@@ -0,0 +1,18 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#ifndef _NGX_MURMURHASH_H_INCLUDED_
+#define _NGX_MURMURHASH_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+uint32_t ngx_murmur_hash2(u_char *data, size_t len);
+
+
+#endif /* _NGX_CRC_H_INCLUDED_ */