3a8baf895dfc6d85a982d05a2fb70cb28e49fec1
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"
19 #if (defined(__GNUC__) && defined(__i386__))
20 # define get16bits(d) (*((const uint16_t *) (d)))
23 #if !defined(get16bits)
24 # define get16bits(d) \
25 ((((uint32_t)(((const uint8_t *) (d))[1])) << 8) + (uint32_t)(((const uint8_t *) (d))[0]))
28 #ifdef HAVE_HSIEH_HASH
29 uint32_t hashkit_hsieh(const char *key
, size_t key_length
, void *) {
30 uint32_t hash
= 0, tmp
;
33 if (key_length
<= 0 || key
== NULL
)
40 for (; key_length
> 0; key_length
--) {
41 hash
+= get16bits(key
);
42 tmp
= (get16bits(key
+ 2) << 11) ^ hash
;
43 hash
= (hash
<< 16) ^ tmp
;
44 key
+= 2 * sizeof(uint16_t);
48 /* Handle end cases */
51 hash
+= get16bits(key
);
53 hash
^= (uint32_t) key
[sizeof(uint16_t)] << 18;
57 hash
+= get16bits(key
);
62 hash
+= (unsigned char) (*key
);
69 /* Force "avalanching" of final 127 bits */
80 uint32_t hashkit_hsieh(const char *, size_t, void *) {