added hash and equality functions for uint64_t
authorDima Kogan <dima@secretsauce.net>
Mon, 2 Jun 2014 06:37:28 +0000 (23:37 -0700)
committerChanho Park <chanho61.park@samsung.com>
Fri, 22 Aug 2014 11:38:26 +0000 (20:38 +0900)
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

dict.c
dict.h

diff --git a/dict.c b/dict.c
index a06e570..c9a449b 100644 (file)
--- a/dict.c
+++ b/dict.c
@@ -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;
diff --git a/dict.h b/dict.h
index 18ad785..a17e1da 100644 (file)
--- a/dict.h
+++ b/dict.h
@@ -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);