X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fhashfunc.c;h=d92b681ee6bbdc667d96d9bc23dd258df6d25063;hb=1481eca416a467e9952dbc5e4852afe66eaf1256;hp=bfd76cfe8b1fad9a5e7076c812085e9ac3562e43;hpb=031256ad2e123eec58521f8e3eb9496c197641d2;p=libucw.git diff --git a/ucw/hashfunc.c b/ucw/hashfunc.c index bfd76cfe..d92b681e 100644 --- a/ucw/hashfunc.c +++ b/ucw/hashfunc.c @@ -11,38 +11,38 @@ * of the GNU Lesser General Public License. */ -#include "ucw/lib.h" -#include "ucw/hashfunc.h" -#include "ucw/chartype.h" +#include +#include +#include /* The number of bits the hash in the function hash_*() is rotated by after * every pass. It should be prime with the word size. */ #define SHIFT_BITS 7 /* A bit-mask which clears higher bytes than a given threshold. */ -static uns mask_higher_bits[sizeof(uns)]; +static uint mask_higher_bits[sizeof(uint)]; static void CONSTRUCTOR hashfunc_init(void) { - uns i, j; + uint i, j; byte *str; - for (i=0; i= sizeof(uns)) + const uint *u = (const uint *) buf; + uint hash = 0; + while (len >= sizeof(uint)) { hash = ROL(hash, SHIFT_BITS) ^ *u++; - len -= sizeof(uns); + len -= sizeof(uint); } hash = ROL(hash, SHIFT_BITS) ^ (*u & mask_higher_bits[len]); return hash; } #ifndef CPU_ALLOW_UNALIGNED -uns +uint str_len(const char *str) { - uns shift = UNALIGNED_PART(str, uns); + uint shift = UNALIGNED_PART(str, uint); if (!shift) return str_len_aligned(str); else { - uns i; - shift = sizeof(uns) - shift; + uint i; + shift = sizeof(uint) - shift; for (i=0; i= len) break; - hash ^= str[i] << (shift * 8); + hash ^= buf[i] << (shift * 8); } return hash; } } #endif -uns +uint hash_string_nocase(const char *str) { const byte *s = str; - uns hash = 0; - uns i; + uint hash = 0; + uint i; for (i=0; ; i++) { - uns modulo = i % sizeof(uns); - uns shift; + uint modulo = i % sizeof(uint); + uint shift; #ifdef CPU_LITTLE_ENDIAN shift = modulo; #else - shift = sizeof(uns) - 1 - modulo; + shift = sizeof(uint) - 1 - modulo; #endif if (!modulo) hash = ROL(hash, SHIFT_BITS);