2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
16 #include "libhashkit/common.h"
18 #ifdef HAVE_MURMUR_HASH
20 # ifdef BYTESWAP_HEADER
21 # include BYTESWAP_HEADER
26 uint32_t hashkit_murmur(const char *key
, size_t length
, void *context
) {
28 'm' and 'r' are mixing constants generated offline. They're not
29 really 'magic', they just happen to work well.
32 const unsigned int m
= 0x5bd1e995;
33 const uint32_t seed
= (0xdeadbeef * (uint32_t) length
);
36 // Initialize the hash to a 'random' value
38 uint32_t h
= seed
^ (uint32_t) length
;
40 // Mix 4 bytes at a time into the hash
42 const unsigned char *data
= (const unsigned char *) key
;
47 memcpy(&k
, data
, sizeof(k
));
63 // Handle the last few bytes of the input array
66 memcpy(&k
, data
, length
);
75 Do a few final mixes of the hash to ensure the last few bytes are
87 uint32_t hashkit_murmur(const char *, size_t, void *) {