]> mj.ucw.cz Git - libucw.git/blobdiff - lib/hashfunc.h
Merged with v3.8
[libucw.git] / lib / hashfunc.h
index ed896e8ebfab7cd968ed085efa6919780dc1cc4c..e60e3f70628f38feaa843374f2e665ef9a3ac7df 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *     Hyper-super-meta-alt-control-shift extra fast str_len() and hash_*()
- *     routines
+ *     UCW Library -- Hyper-super-meta-alt-control-shift extra fast
+ *     str_len() and hash_*() routines
  *
  *     (c) 2002, Robert Spalek <robert@ucw.cz>
  *
@@ -13,9 +13,6 @@
 
 #include "lib/lib.h"
 
-/* An equivalent of the Intel's rol instruction.  */
-#define        ROL(x, bits)    (((x) << (bits)) | ((x) >> (sizeof(uns)*8 - (bits))))
-
 /* The following functions need str to be aligned to uns.  */
 uns str_len_aligned(const byte *str) CONST;
 uns hash_string_aligned(const byte *str) CONST;
@@ -39,7 +36,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)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