]> mj.ucw.cz Git - libucw.git/commitdiff
Added hash functions for 64-bit integers.
authorMartin Mares <mj@ucw.cz>
Thu, 16 Jun 2005 21:03:13 +0000 (21:03 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 16 Jun 2005 21:03:13 +0000 (21:03 +0000)
hash_pointer() now uses either 32-bit or 64-bit hash depending on pointer size.
hashtable.h with an atomic key does the same.

lib/hash-test.c
lib/hashfunc.h
lib/hashtable.h

index af4c7154d1f911705b0d5b74d2626c1c970f2134..31af3c0fbde76cc4d48c298fd660f4caaa6acd3f 100644 (file)
@@ -171,7 +171,7 @@ struct node4 {
 #define HASH_GIVE_HASHFN
 static uns test4_hash(char *host, int port)
 {
-  return hash_string_nocase(host) ^ hash_int(port);
+  return hash_string_nocase(host) ^ hash_u32(port);
 }
 
 #define HASH_GIVE_EQ
index 17a865b19184c0ca301db4f173d6d37bead3a39c..c10f224910d9ba563ef401adc45ae57db011912a 100644 (file)
@@ -39,7 +39,8 @@ uns hash_string_nocase(const byte *str) CONST;
  *  of using shifts and adds on architectures where multiplication
  *  instructions are slow).
  */
-static inline uns CONST hash_int(uns x) { return 0x01008041*x; }
-static inline uns CONST hash_pointer(void *x) { return hash_int((uns)(addr_int_t)x); }
+static inline uns CONST hash_u32(uns x) { return 0x01008041*x; }
+static inline uns CONST hash_u64(u64 x) { return hash_u32((uns)x ^ (uns)(x >> 32)); }
+static inline uns CONST hash_pointer(void *x) { return ((sizeof(x) <= 4) ? hash_u32((uns)(addr_int_t)x) : hash_u64((u64)(addr_int_t)x)); }
 
 #endif
index 549eca82dfc3bbd4a5862886dba8209e3b0aa09d..2893e998ddefb7d82ce3ebcfde217b09f5eabce6 100644 (file)
@@ -185,7 +185,7 @@ struct P(table) P(table);
 #ifndef HASH_GIVE_HASHFN
 #  define HASH_GIVE_HASHFN
    static inline int P(hash) (TAUC HASH_ATOMIC_TYPE x)
-   { return hash_int(x); }
+   { return ((sizeof(x) <= 4) ? hash_u32(x) : hash_u64(x)); }
 #endif
 
 #ifndef HASH_GIVE_EQ