12 uint32_t cx_hash_u32(uint32_t x); |
12 uint32_t cx_hash_u32(uint32_t x); |
13 uint64_t cx_hash_u64(uint64_t x); |
13 uint64_t cx_hash_u64(uint64_t x); |
14 |
14 |
15 CxHashKey cx_hash_key(const void *obj, size_t len); |
15 CxHashKey cx_hash_key(const void *obj, size_t len); |
16 CxHashKey cx_hash_key_str(const char *str); |
16 CxHashKey cx_hash_key_str(const char *str); |
|
17 CxHashKey cx_hash_key_ustr(const unsigned char *str); |
17 CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len); |
18 CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len); |
18 CxHashKey cx_hash_key_cxstr(cxstring str); |
19 CxHashKey cx_hash_key_cxstr(cxstring str); |
19 CxHashKey cx_hash_key_u32(uint32_t x); |
20 CxHashKey cx_hash_key_u32(uint32_t x); |
20 CxHashKey cx_hash_key_u64(uint64_t x); |
21 CxHashKey cx_hash_key_u64(uint64_t x); |
21 |
22 |
27 The primary function for creating a `CxHashKey` structure from non-integers is `cx_hash_key()`. |
28 The primary function for creating a `CxHashKey` structure from non-integers is `cx_hash_key()`. |
28 The other functions effectively do the same, but |
29 The other functions effectively do the same, but |
29 |
30 |
30 * `cx_hash_key_bytes()` is strongly typed if you want to avoid passing `void*` |
31 * `cx_hash_key_bytes()` is strongly typed if you want to avoid passing `void*` |
31 * `cx_hash_key_str()` conveniently takes a C string and computes the length |
32 * `cx_hash_key_str()` conveniently takes a C string and computes the length |
|
33 * `cx_hash_key_ustr()` same as before, but for `unsigned char*` |
32 * `cx_hash_key_cxstr()` conveniently takes a [UCX string](string.h.md) |
34 * `cx_hash_key_cxstr()` conveniently takes a [UCX string](string.h.md) |
33 |
35 |
34 In all cases, the hash will be available in the `hash` field of the returned structure. |
36 In all cases, the hash will be available in the `hash` field of the returned structure. |
35 |
37 |
|
38 > Usually you will never need to call any of the other functions directly. |
|
39 > You can always create a `CxHashKey` structure by using the `CX_HASH_KEY()` macro |
|
40 > (when the length of the key is implicitly clear) or by using the `cx_hash_key()` function. |
|
41 > {style="note"} |
|
42 |
36 > UCX assigns the hash value `1574210520` to the `NULL` pointer. |
43 > UCX assigns the hash value `1574210520` to the `NULL` pointer. |
37 > This is a careful choice which is not standard MurmurHash2 and an extension to support `NULL` pointers. |
44 > This is a careful choice which is not standard MurmurHash2 and an extension to support `NULL` pointers. |
|
45 |
|
46 Hashes from integers are created more efficiently by mixing up the bits to produce a good statistical distribution. |
|
47 The function `cx_hash_u32()` and `cx_hash_u64()` are provided for this purpose and provide collision-free hashes. |
|
48 The corresponding functions `cx_hash_key_u32()` and `cx_hash_key_u64()` can be used to create `CxHashKey` structures with those hashes. |
|
49 |
|
50 > Since integer hashes are collision-free, there is no need to store any `data` in the `CxHashKey` structure. |
38 |
51 |
39 If you want to create a hash completely manually, |
52 If you want to create a hash completely manually, |
40 you can initialize the `data` and `len` members of `CxHashKey` |
53 you can initialize the `data` and `len` members of `CxHashKey` |
41 and call `cx_hash_murmur()`. |
54 and call `cx_hash_murmur()`. |
42 It is _not_ recommended to do so. |
55 It is _not_ recommended to do so. |
47 key.data = mystring; |
60 key.data = mystring; |
48 key.len = strlen(mystring); |
61 key.len = strlen(mystring); |
49 cx_hash_murmur(&key); |
62 cx_hash_murmur(&key); |
50 ``` |
63 ``` |
51 |
64 |
52 Hashes from integers are created more efficiently by mixing up the bits to produce a good statistical distribution. |
|
53 The function `cx_hash_u32()` and `cx_hash_u64()` are provided for this purpose and provide collision-free hashes. |
|
54 The corresponding functions `cx_hash_key_u32()` and `cx_hash_key_u64()` can be used to create `CxHashKey` structures with those hashes. |
|
55 |
|
56 > Since integer hashes are collision-free, there is no need to store any `data` in the `CxHashKey` structure. |
|
57 |
|
58 Hash keys are compared with `cx_hash_key_cmp()`. |
65 Hash keys are compared with `cx_hash_key_cmp()`. |
59 |
66 |
60 <seealso> |
67 <seealso> |
61 <category ref="apidoc"> |
68 <category ref="apidoc"> |
62 <a href="https://ucx.sourceforge.io/api/hash__key_8h.html">hash_key.h</a> |
69 <a href="https://ucx.sourceforge.io/api/hash__key_8h.html">hash_key.h</a> |