Configuration/Hash_Keyword [ Functions ]
FUNCTION
Calculate the hash value for a string
The hash value is a 32 bit integer based on the hash function written by Bob Jenkins. It is then reduced by an AND operation to the actual size of the hash table.
SYNOPSIS
unsigned long Hash_Keyword( char *key, unsigned long keylen )
INPUTS
- key -- The keyword string
- keylen -- The length of the keyword string
RETURN VALUE
The hash value for the keyword.
SOURCE
{ unsigned long bkt, i, j, k; bkt = 0xfeedbeef; i = j = 0x9e3779b9; k = keylen; while ( k >= 12 ) { i += ( key[0] + ( ( unsigned ) key[1] << 8 ) + ( ( unsigned ) key[2] << 16 ) + ( ( unsigned ) key[3] << 24 ) ); j += ( key[4] + ( ( unsigned ) key[5] << 8 ) + ( ( unsigned ) key[6] << 16 ) + ( ( unsigned ) key[7] << 24 ) ); bkt += ( key[8] + ( ( unsigned ) key[9] << 8 ) + ( ( unsigned ) key[10] << 16 ) + ( ( unsigned ) key[11] << 24 ) ); HASH_MIX( i, j, bkt ); key += 12; k -= 12; } bkt += keylen; switch ( k ) { case 11: bkt += ( ( unsigned ) key[10] << 24 ); case 10: bkt += ( ( unsigned ) key[9] << 16 ); case 9: bkt += ( ( unsigned ) key[8] << 8 ); case 8: j += ( ( unsigned ) key[7] << 24 ); case 7: j += ( ( unsigned ) key[6] << 16 ); case 6: j += ( ( unsigned ) key[5] << 8 ); case 5: j += key[4]; case 4: i += ( ( unsigned ) key[3] << 24 ); case 3: i += ( ( unsigned ) key[2] << 16 ); case 2: i += ( ( unsigned ) key[1] << 8 ); case 1: i += key[0]; } HASH_MIX( i, j, bkt ); return ( bkt & keywords_hash_mask ); }