hashing 

Send to Kindle
home » snippets » hashing



Snippets

bitwisehash.c

/* Author J. Zobel, April 2001.
   Permission to use this code is freely granted, provided that this
   statement is retained. */

/* Modified by chirayu for personal quick readibility. */

/* Bitwise hash function.  Note that tsize does not have to be prime. */
unsigned int bitwisehash(char *word, int tsize, unsigned int seed) {
    char c;
    for (unsigned int h=seed; (c=*word) != '\0'; word++) {
        h ^= ( (h << 5) + c + (h >> 2) );
    }
    h = (h & 0x7fffffff) % tsize;
    return ((unsigned int) h);
}