← Back to C-Kernel-Engine Docs Doxygen Source Documentation
murmurhash3.h
Go to the documentation of this file.
1 /*
2  * MurmurHash3 - 32-bit and 128-bit versions
3  *
4  * Ported from HPC_Embeddings for use in C-Kernel-Engine tokenizer.
5  * Provides consistent, high-quality hashing for vocabulary lookups.
6  *
7  * Original by Austin Appleby, ported for C-Kernel-Engine.
8  */
9 
10 #ifndef CK_MURMURHASH3_H
11 #define CK_MURMURHASH3_H
12 
13 #include <stdint.h>
14 #include <stddef.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /**
21  * MurmurHash3-32bit hash function (original HPC_Embeddings version).
22  *
23  * @param key Data to hash
24  * @param len Length in bytes
25  * @param seed Seed value
26  * @return 32-bit hash value
27  */
28 uint32_t ck_murmurhash3(const char *key, uint32_t len, uint32_t seed);
29 
30 /**
31  * MurmurHash3-32bit hash function (alternative name).
32  *
33  * @param key Data to hash
34  * @param len Length in bytes
35  * @param seed Optional seed value (use 0 for default)
36  * @return 32-bit hash value
37  */
38 uint32_t ck_murmurhash3_32(const void *key, size_t len, uint32_t seed);
39 
40 /**
41  * MurmurHash3-128bit hash function (produces two 64-bit values).
42  *
43  * @param key Data to hash
44  * @param len Length in bytes
45  * @param seed Optional seed value (use 0 for default)
46  * @param out1 First 64 bits of hash output
47  * @param out2 Second 64 bits of hash output
48  */
49 void ck_murmurhash3_128(const void *key, size_t len, uint32_t seed,
50  uint64_t *out1, uint64_t *out2);
51 
52 /**
53  * MurmurHash3-32bit for string (null-terminated).
54  */
55 static inline uint32_t ck_murmurhash3_str(const char *str, uint32_t seed) {
56  return ck_murmurhash3_32(str, strlen(str), seed);
57 }
58 
59 /**
60  * MurmurHash3-32bit for string with length.
61  */
62 static inline uint32_t ck_murmurhash3_strn(const char *str, size_t len, uint32_t seed) {
63  return ck_murmurhash3(str, len, seed);
64 }
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif /* CK_MURMURHASH3_H */
static uint32_t ck_murmurhash3_strn(const char *str, size_t len, uint32_t seed)
Definition: murmurhash3.h:62
uint32_t ck_murmurhash3_32(const void *key, size_t len, uint32_t seed)
Definition: murmurhash3.c:68
void ck_murmurhash3_128(const void *key, size_t len, uint32_t seed, uint64_t *out1, uint64_t *out2)
uint32_t ck_murmurhash3(const char *key, uint32_t len, uint32_t seed)
Definition: murmurhash3.c:11
static uint32_t ck_murmurhash3_str(const char *str, uint32_t seed)
Definition: murmurhash3.h:55