# HG changeset patch # User Olaf Wintermann # Date 1667750379 -3600 # Node ID e2093ca0ef901a69614fd6a18ba410b6fdad6821 # Parent d938228c382eeb99dcc8317c49a0c48a2d7fcce7 update ucx hash functions diff -r d938228c382e -r e2093ca0ef90 src/ucx/cx/hash_key.h --- a/src/ucx/cx/hash_key.h Sun Nov 06 15:53:32 2022 +0100 +++ b/src/ucx/cx/hash_key.h Sun Nov 06 16:59:39 2022 +0100 @@ -50,9 +50,10 @@ union { unsigned char *bytes; unsigned char const *cbytes; + char *str; char const *cstr; - char *str; void *obj; + void const *cobj; } data; /** * The key data length. @@ -68,11 +69,13 @@ typedef struct cx_hash_key_s CxHashKey; /** - * Computes a murmur hash-2. + * Computes a murmur2 32 bit hash. * - * You need to initialize data and len in the key struct. + * You need to initialize \c data and \c len in the key struct. * The hash is then directly written to that struct. * + * \note If \c data is \c NULL, the hash is defined as 1574210520. + * * @param key the key, the hash shall be computed for */ void cx_hash_murmur(CxHashKey *key); @@ -114,7 +117,7 @@ */ __attribute__((__warn_unused_result__)) CxHashKey cx_hash_key( - void *obj, + void const *obj, size_t len ); diff -r d938228c382e -r e2093ca0ef90 src/ucx/hash_key.c --- a/src/ucx/hash_key.c Sun Nov 06 15:53:32 2022 +0100 +++ b/src/ucx/hash_key.c Sun Nov 06 16:59:39 2022 +0100 @@ -30,8 +30,13 @@ #include void cx_hash_murmur(CxHashKey *key) { + unsigned char const *data = key->data.cbytes; + if (data == NULL) { + /* extension: special value for NULL */ + key->hash = 1574210520u; + return; + } size_t len = key->len; - unsigned char const *data = key->data.cbytes; unsigned m = 0x5bd1e995; unsigned r = 24; @@ -96,11 +101,11 @@ } CxHashKey cx_hash_key( - void *obj, + void const *obj, size_t len ) { CxHashKey key; - key.data.obj = obj; + key.data.cobj = obj; key.len = len; cx_hash_murmur(&key); return key;