Tue, 30 Sep 2025 22:35:24 +0200
finalize the documentation on the new hash key features
resolves #731
docs/Writerside/topics/hash_key.h.md | file | annotate | diff | comparison | revisions |
--- a/docs/Writerside/topics/hash_key.h.md Tue Sep 30 22:29:54 2025 +0200 +++ b/docs/Writerside/topics/hash_key.h.md Tue Sep 30 22:35:24 2025 +0200 @@ -14,6 +14,7 @@ CxHashKey cx_hash_key(const void *obj, size_t len); CxHashKey cx_hash_key_str(const char *str); +CxHashKey cx_hash_key_ustr(const unsigned char *str); CxHashKey cx_hash_key_bytes(const unsigned char *bytes, size_t len); CxHashKey cx_hash_key_cxstr(cxstring str); CxHashKey cx_hash_key_u32(uint32_t x); @@ -29,13 +30,25 @@ * `cx_hash_key_bytes()` is strongly typed if you want to avoid passing `void*` * `cx_hash_key_str()` conveniently takes a C string and computes the length +* `cx_hash_key_ustr()` same as before, but for `unsigned char*` * `cx_hash_key_cxstr()` conveniently takes a [UCX string](string.h.md) In all cases, the hash will be available in the `hash` field of the returned structure. +> Usually you will never need to call any of the other functions directly. +> You can always create a `CxHashKey` structure by using the `CX_HASH_KEY()` macro +> (when the length of the key is implicitly clear) or by using the `cx_hash_key()` function. +> {style="note"} + > UCX assigns the hash value `1574210520` to the `NULL` pointer. > This is a careful choice which is not standard MurmurHash2 and an extension to support `NULL` pointers. +Hashes from integers are created more efficiently by mixing up the bits to produce a good statistical distribution. +The function `cx_hash_u32()` and `cx_hash_u64()` are provided for this purpose and provide collision-free hashes. +The corresponding functions `cx_hash_key_u32()` and `cx_hash_key_u64()` can be used to create `CxHashKey` structures with those hashes. + +> Since integer hashes are collision-free, there is no need to store any `data` in the `CxHashKey` structure. + If you want to create a hash completely manually, you can initialize the `data` and `len` members of `CxHashKey` and call `cx_hash_murmur()`. @@ -49,12 +62,6 @@ cx_hash_murmur(&key); ``` -Hashes from integers are created more efficiently by mixing up the bits to produce a good statistical distribution. -The function `cx_hash_u32()` and `cx_hash_u64()` are provided for this purpose and provide collision-free hashes. -The corresponding functions `cx_hash_key_u32()` and `cx_hash_key_u64()` can be used to create `CxHashKey` structures with those hashes. - -> Since integer hashes are collision-free, there is no need to store any `data` in the `CxHashKey` structure. - Hash keys are compared with `cx_hash_key_cmp()`. <seealso>