X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fhashfunc.h;h=cc799476a87938e6349e786c6b6f4d72de9c2df1;hb=8107422b6cc0fda08e55218a3a79ff1580779a95;hp=d79e44ecfdaf695439a026496287ccab2e9ef76b;hpb=b0cbde12a98264c2629b52f618678e7f1eacf097;p=libucw.git diff --git a/lib/hashfunc.h b/lib/hashfunc.h index d79e44ec..cc799476 100644 --- a/lib/hashfunc.h +++ b/lib/hashfunc.h @@ -3,6 +3,9 @@ * routines * * (c) 2002, Robert Spalek + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ #ifndef _SHERLOCK_HASHFUNC_H @@ -30,6 +33,13 @@ uns hash_block(const byte *str, uns len) CONST; uns hash_string_nocase(const byte *str) CONST; -static inline uns CONST hash_int(uns x) { return 6442450967*x; } +/* + * We hash integers by multiplying by a reasonably large prime with + * few ones in its binary form (to gave the compiler the possibility + * 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); } #endif