diff options
author | Igor Sysoev <igor@sysoev.ru> | 2011-04-15 14:59:24 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2011-04-15 14:59:24 +0400 |
commit | 42f1e1cb96b510d1fa1abad99a5294a37b750d99 (patch) | |
tree | 1726743418ae2546c84419f7bd22f603557f2409 /src/core | |
parent | 0bd0b2894c6f2514e53b940f6d64cbe5198a4d6c (diff) |
ngx_murmur_hash2()
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ngx_core.h | 1 | ||||
-rw-r--r-- | src/core/ngx_murmurhash.c | 50 | ||||
-rw-r--r-- | src/core/ngx_murmurhash.h | 18 |
3 files changed, 69 insertions, 0 deletions
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h index 5939166af..9f1790153 100644 --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -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 index 000000000..c31e0e035 --- /dev/null +++ b/src/core/ngx_murmurhash.c @@ -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 index 000000000..ae40779d4 --- /dev/null +++ b/src/core/ngx_murmurhash.h @@ -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_ */ |