Changeset 226 for cpp/frams


Ignore:
Timestamp:
04/18/14 01:51:17 (11 years ago)
Author:
Maciej Komosinski
Message:
  • SString::hash() and HashTable? use FNV-1a instead of FNV-1
  • fixed the initial hash value
Location:
cpp/frams/util
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/hashtable.cpp

    r197 r226  
    55#include "hashtable.h"
    66
    7 int HashTable::hash(const char *s)
     7int HashTable::hash(const SString &s)
    88{
    9 int h=0;
    10 char c;
    11 while(c=*(s++))
    12     h=31*h+c;
    13 return h&0x7fffffff;
     9return s.hash()&0x7fffffff;
    1410}
    1511
  • cpp/frams/util/hashtable.h

    r197 r226  
    3131long sync;
    3232
    33 int hash(const char *s);
     33int hash(const SString &s);
    3434void rehash(int newsize);
    3535public:
  • cpp/frams/util/sstring.cpp

    r222 r226  
    116116
    117117#define FNV_32_PRIME ((Fnv32_t)0x01000193)
    118 
    119 Fnv32_t fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
     118#define FNV1_32_INIT ((Fnv32_t)0x811c9dc5)
     119#define FNV1_32A_INIT FNV1_32_INIT
     120
     121Fnv32_t fnv_32a_buf(void *buf, size_t len, Fnv32_t hval)
    120122{
    121123    unsigned char *bp = (unsigned char *)buf;   /* start of buffer */
     
    123125
    124126    while (bp < be) {
     127
     128        /* xor the bottom with the current octet */
     129        hval ^= (Fnv32_t)*bp++;
    125130
    126131        /* multiply by the 32 bit FNV magic prime mod 2^32 */
     
    131136#endif
    132137
    133         /* xor the bottom with the current octet */
    134         hval ^= (Fnv32_t)*bp++;
    135138    }
    136139
     
    142145unsigned long SBuf::hash() const
    143146{
    144 return fnv_32_buf(txt,used,FNV_32_PRIME);
     147return fnv_32a_buf(txt,used,FNV1_32A_INIT);
    145148}
    146149
Note: See TracChangeset for help on using the changeset viewer.