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

Legend:

Unmodified
Added
Removed
  • 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.