ccutil/hashfn.h File Reference

#include "host.h"

Go to the source code of this file.

Functions


Function Documentation

INT32 hash ( INT32  bits,
void *  key,
INT32  keysize 
)

Simple hash function working on power of 2 table sizes.

Uses xor function. Needs linear rehash.

See http://en.wikipedia.org/wiki/Hash_table

Definition at line 30 of file hashfn.cpp.

Referenced by MALLOC_CALL::count_freeer(), and MEM_ALLOCATOR::hash_caller().

00034             {
00035   INT32 bitindex;                //current bit count
00036   UINT32 keybits;                //bit buffer
00037   UINT32 hcode;                  //current hash code
00038   UINT32 mask;                   //bit mask
00039 
00040   mask = (1 << bits) - 1;
00041   keysize *= 8;                  //in bits
00042   bitindex = 0;
00043   keybits = 0;
00044   hcode = 0;
00045   do {
00046     while (keysize > 0 && bitindex <= 24) {
00047       keybits |= *((UINT8 *) key) << bitindex;
00048       key = (UINT8 *) key + 1;
00049       bitindex += 8;
00050       keysize -= 8;
00051     }
00052     hcode ^= keybits & mask;     //key new key
00053     keybits >>= bits;
00054   }
00055   while (keysize > 0);
00056   return hcode;                  //initial hash
00057 }


Generated on Wed Feb 28 19:49:16 2007 for Tesseract by  doxygen 1.5.1