[ltrace-commits] 02/03: added hash and equality functions for uint64_t

Petr Machata pmachata-guest at moszumanska.debian.org
Tue Jun 17 18:41:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

pmachata-guest pushed a commit to branch master
in repository ltrace.

commit ac6ef933779720830c4518e35e07620231fb61b8
Author: Dima Kogan <dima at secretsauce.net>
Date:   Sun Jun 1 23:37:28 2014 -0700

    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
---
 dict.c | 16 ++++++++++++++++
 dict.h |  7 +++++++
 2 files changed, 23 insertions(+)

diff --git a/dict.c b/dict.c
index a06e570..c9a449b 100644
--- 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
--- 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);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/ltrace.git



More information about the ltrace-commits mailing list