--- a/src/cx/hash_key.h Sat Sep 27 17:47:10 2025 +0200 +++ b/src/cx/hash_key.h Sat Sep 27 17:49:13 2025 +0200 @@ -46,14 +46,17 @@ /** Internal structure for a key within a hash map. */ struct cx_hash_key_s { - /** The key data. */ + /** + * The key data. + * May be NULL when the hash is collision-free. + */ const void *data; /** * The key data length. */ size_t len; /** The hash value of the key data. */ - unsigned hash; + uint64_t hash; }; /** @@ -80,6 +83,48 @@ void cx_hash_murmur(CxHashKey *key); /** + * Mixes up a 32-bit integer to be used as a hash. + * + * This function produces no collisions and has a good statistical distribution. + * + * @param x the integer + * @return the hash + */ +cx_attr_export +uint32_t cx_hash_u32(uint32_t x); + +/** + * Mixes up a 64-bit integer to be used as a hash. + * + * This function produces no collisions and has a good statistical distribution. + * + * @param x the integer + * @return the hash + */ +cx_attr_export +uint64_t cx_hash_u64(uint64_t x); + +/** + * Computes a hash key from a 32-bit integer. + * + * @param x the integer + * @return the hash key + */ +cx_attr_nodiscard +cx_attr_export +CxHashKey cx_hash_key_u32(uint32_t x); + +/** + * Computes a hash key from a 64-bit integer. + * + * @param x the integer + * @return the hash key + */ +cx_attr_nodiscard +cx_attr_export +CxHashKey cx_hash_key_u64(uint64_t x); + +/** * Computes a hash key from a string. * * The string needs to be zero-terminated. @@ -145,6 +190,18 @@ */ #define cx_hash_key_cxstr(str) cx_hash_key_cxstr(cx_strcast(str)) +/** + * Compare function for hash keys. + * + * @param left the first key + * @param right the second key + * @return zero when the keys equal, non-zero when they differ + */ +cx_attr_nodiscard +cx_attr_nonnull +cx_attr_export +int cx_hash_key_cmp(const CxHashKey *left, const CxHashKey *right); + #ifdef __cplusplus } // extern "C" #endif