diff options
author | Dima Kogan <dima@secretsauce.net> | 2014-06-01 23:37:28 -0700 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-08-22 20:38:26 +0900 |
commit | c72ced175870b1dc727171867bfa0854862e8199 (patch) | |
tree | 6806b51473169ec8eb549a08bd08b4b77ec79604 | |
parent | b3fd645cb02de43ad3bd5c803c2c89350ac611d7 (diff) | |
download | ltrace-c72ced175870b1dc727171867bfa0854862e8199.tar.gz ltrace-c72ced175870b1dc727171867bfa0854862e8199.tar.bz2 ltrace-c72ced175870b1dc727171867bfa0854862e8199.zip |
added hash and equality functions for uint64_t
The hash function is identical to the 32-bit signed int hash function. This
function is unideal for such extended use, but is sufficient for now
-rw-r--r-- | dict.c | 16 | ||||
-rw-r--r-- | dict.h | 7 |
2 files changed, 23 insertions, 0 deletions
@@ -474,6 +474,22 @@ dict_eq_int(const int *key1, const int *key2) } size_t +dict_hash_uint64(const uint64_t *key) +{ + // I use the same hash function as for 32-bit signed integers. This + // probably will not have great performance for values that don't fit + // into a 32-bit signed int, but this will do for now + int key32 = (int)(*key); + return dict_hash_int(&key32); +} + +int +dict_eq_uint64(const uint64_t *key1, const uint64_t *key2) +{ + return *key1 == *key2; +} + +size_t dict_hash_string(const char **key) { size_t h = 5381; @@ -22,6 +22,7 @@ #define _DICT_H_ #include <stddef.h> +#include <stdint.h> #include <assert.h> #include "vect.h" @@ -231,6 +232,12 @@ size_t dict_hash_int(const int *key); /* An equality predicate callback for integers. */ int dict_eq_int(const int *key1, const int *key2); +/* A callback for hashing uint64_t. */ +size_t dict_hash_uint64(const uint64_t *key); + +/* An equality predicate callback for uint64_t. */ +int dict_eq_uint64(const uint64_t *key1, const uint64_t *key2); + /* A callback for hashing NULL-terminated strings. */ size_t dict_hash_string(const char **key); |