💾 Archived View for gemini.rmf-dev.com › repo › Vaati › gmi_proxy › files › 6844a0bc28144eaa69938ad0… captured on 2023-04-19 at 23:45:43. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
0 /*
1 * MurmurHash3 was written by Austin Appleby, and is placed in the public
2 * domain. The author hereby disclaims copyright to this source code.
3 */
4
5 #include <stdint.h>
6 #include "murmur3.h"
7
8 #define ROTL32(x,r) ((x << r) | (x >> (32 - r)))
9 #define CONST1 0xcc9e2d51
10 #define CONST2 0x1b873593
11
12 uint32_t murmur3(const void *key, int len, uint32_t seed) {
13
14 const uint8_t *data = (const uint8_t*)key;
15 const int nblocks = len / 4;
16 int i;
17
18 uint32_t h1 = seed, k1;
19
20 const uint32_t *blocks;
21 const uint8_t *tail;
22
23 blocks = (const uint32_t*)(data + nblocks * 4);
24
25 for (i = -nblocks; i; i++) {
26 k1 = blocks[i];
27
28 k1 *= CONST1;
29 k1 = ROTL32(k1, 15);
30 k1 *= CONST2;
31
32 h1 ^= k1;
33 h1 = ROTL32(h1, 13);
34 h1 = h1 * 5 + 0xe6546b64;
35 }
36
37 tail = (const uint8_t*)(data + nblocks * 4);
38
39 k1 = 0;
40
41 switch (len & 3) {
42 case 3:
43 k1 ^= tail[2] << 16;
44 /* fallthrough */
45 case 2:
46 k1 ^= tail[1] << 8;
47 /* fallthrough */
48 case 1:
49 k1 ^= tail[0];
50 k1 *= CONST1;
51 k1 = ROTL32(k1, 15);
52 k1 *= CONST2;
53 h1 ^= k1;
54 };
55
56 h1 ^= len;
57
58 h1 ^= h1 >> 16;
59 h1 *= 0x85ebca6b;
60 h1 ^= h1 >> 13;
61 h1 *= 0xc2b2ae35;
62 h1 ^= h1 >> 16;
63
64 return h1;
65 }
66