X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fhashfunc.h;h=a9fb1a315df182169ef734644e8ab408de5f352a;hb=ab3b3f178718c0ae7b5738e987e350537574d2e6;hp=cc799476a87938e6349e786c6b6f4d72de9c2df1;hpb=b61d2a84d852c9ef08e252d79c5f5feb48826271;p=libucw.git diff --git a/lib/hashfunc.h b/lib/hashfunc.h index cc799476..a9fb1a31 100644 --- a/lib/hashfunc.h +++ b/lib/hashfunc.h @@ -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 * @@ -8,30 +8,27 @@ * of the GNU Lesser General Public License. */ -#ifndef _SHERLOCK_HASHFUNC_H -#define _SHERLOCK_HASHFUNC_H +#ifndef _UCW_HASHFUNC_H +#define _UCW_HASHFUNC_H #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; -uns hash_block_aligned(const byte *str, uns len) CONST; +uns str_len_aligned(const char *str) PURE; +uns hash_string_aligned(const char *str) PURE; +uns hash_block_aligned(const byte *str, uns len) PURE; #ifdef CPU_ALLOW_UNALIGNED #define str_len(str) str_len_aligned(str) #define hash_string(str) hash_string_aligned(str) #define hash_block(str, len) hash_block_aligned(str, len) #else -uns str_len(const byte *str) CONST; -uns hash_string(const byte *str) CONST; -uns hash_block(const byte *str, uns len) CONST; +uns str_len(const char *str) PURE; +uns hash_string(const char *str) PURE; +uns hash_block(const byte *str, uns len) PURE; #endif -uns hash_string_nocase(const byte *str) CONST; +uns hash_string_nocase(const char *str) PURE; /* * We hash integers by multiplying by a reasonably large prime with @@ -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)(uintptr_t)x) : hash_u64((u64)(uintptr_t)x)); } #endif