1 # Hash Function |
1 # Hash Function |
2 |
2 |
3 ## Undocumented Symbols (TODO) |
3 UCX implements the MurmurHash2 algorithm for computing hashes that are primarily used for [CxMap](map.h.md). |
4 ### cx_hash_key |
4 But it can be used for arbitrary custom scenarios, too. |
5 ### cx_hash_key_bytes |
5 |
6 ### cx_hash_key_str |
6 There are four functions which all generate a `CxHashKey` structure for given data. |
7 ### cx_hash_murmur |
7 |
|
8 * `cx_hash_key()` takes an arbitrary pointer and a length |
|
9 * `cx_hash_key_bytes()` takes an `unsigned char*` and a length |
|
10 * `cx_hash_key_str()` takes a usual C string |
|
11 * `cx_hash_key_cxstr()` takes a [UCX string](string.h.md) |
|
12 |
|
13 The hash is then available in the `hash` field of the returned structure. |
|
14 |
|
15 <note> |
|
16 UCX assigns the hash value <code>1574210520</code> to the <code>NULL</code> pointer. |
|
17 This is a careful choice which is not standard MurmurHash2 and an extension to support <code>NULL</code> pointers. |
|
18 </note> |
|
19 |
|
20 If you want to create a hash completely manually, |
|
21 you can initialize the `data` and `len` members of `CxHashKey` |
|
22 and call `cx_hash_murmur()`. |
|
23 It is _not_ recommended to do so. |
|
24 |
|
25 Example that is equivalent to `CxHashKey key = cx_hash_str(mystring)` |
|
26 ```C |
|
27 CxHashKey key; |
|
28 key.data = mystring; |
|
29 key.len = strlen(mystring); |
|
30 cx_hash_murmur(&key); |
|
31 ``` |