ccutil/hashfn.cpp

Go to the documentation of this file.
00001 
00020 #include          "mfcpch.h"     //precompiled headers
00021 #include          "hashfn.h"
00022 
00030 INT32 hash(               //hash function
00031            INT32 bits,    //bits in hash function
00032            void *key,     //key to hash
00033            INT32 keysize  //size of key
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:09 2007 for Tesseract by  doxygen 1.5.1