← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
murmurhash3.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

uint32_t ck_murmurhash3 (const char *key, uint32_t len, uint32_t seed)
 
uint32_t ck_murmurhash3_32 (const void *key, size_t len, uint32_t seed)
 
static uint32_t ck_murmurhash3_str (const char *key, uint32_t seed)
 

Function Documentation

◆ ck_murmurhash3()

uint32_t ck_murmurhash3 ( const char *  key,
uint32_t  len,
uint32_t  seed 
)

MurmurHash3-32bit hash function (original HPC_Embeddings version).

Parameters
keyData to hash
lenLength in bytes
seedSeed value
Returns
32-bit hash value

Definition at line 11 of file murmurhash3.c.

11 {
12 const uint32_t c1 = 0xcc9e2d51;
13 const uint32_t c2 = 0x1b873593;
14 const uint32_t r1 = 15;
15 const uint32_t r2 = 13;
16 const uint32_t m = 5;
17 const uint32_t n = 0xe6546b64;
18
19 uint32_t hash = seed;
20
21 const int nblocks = len / 4;
22 const uint32_t *blocks = (const uint32_t *)(key);
23 int i;
24 for (i = 0; i < nblocks; i++) {
25 uint32_t k = blocks[i];
26
27 k *= c1;
28 k = (k << r1) | (k >> (32 - r1));
29 k *= c2;
30
31 hash ^= k;
32 hash = (hash << r2) | (hash >> (32 - r2));
33 hash = hash * m + n;
34 }
35
36 const uint8_t *tail = (const uint8_t *)(key + nblocks * 4);
37 uint32_t k1 = 0;
38
39 switch (len & 3) {
40 case 3:
41 k1 ^= tail[2] << 16;
42 case 2:
43 k1 ^= tail[1] << 8;
44 case 1:
45 k1 ^= tail[0];
46 k1 *= c1;
47 k1 = (k1 << r1) | (k1 >> (32 - r1));
48 k1 *= c2;
49 hash ^= k1;
50 }
51
52 hash ^= len;
53 hash ^= hash >> 16;
54 hash *= 0x85ebca6b;
55 hash ^= hash >> 13;
56 hash *= 0xc2b2ae35;
57 hash ^= hash >> 16;
58
59 return hash;
60}

Referenced by ck_murmurhash3_32(), ck_murmurhash3_str(), ck_murmurhash3_strn(), and ck_tokenizer_hash().

◆ ck_murmurhash3_32()

uint32_t ck_murmurhash3_32 ( const void *  key,
size_t  len,
uint32_t  seed 
)

MurmurHash3-32bit hash function (alternative name).

Parameters
keyData to hash
lenLength in bytes
seedOptional seed value (use 0 for default)
Returns
32-bit hash value

Definition at line 68 of file murmurhash3.c.

68 {
69 return ck_murmurhash3((const char *)key, (uint32_t)len, seed);
70}
uint32_t ck_murmurhash3(const char *key, uint32_t len, uint32_t seed)
Definition murmurhash3.c:11

References ck_murmurhash3().

Referenced by ck_murmurhash3_str().

◆ ck_murmurhash3_str()

static uint32_t ck_murmurhash3_str ( const char *  key,
uint32_t  seed 
)
inlinestatic

Definition at line 63 of file murmurhash3.c.

63 {
64 return ck_murmurhash3(key, (uint32_t)strlen(key), seed);
65}

References ck_murmurhash3().