fnv全称”Fowler/Noll/Vo”,特点是快速而且冲突率比较低,在url hostname或者ip的哈希有广泛的应用, 详细信息请点击这里

下面是fnv在Sheepdog中用法的实现,将任意字符串转化为uint64_t

  /*
   * 64 bit FNV-1a non-zero initial basis
   */
  #define FNV1A_64_INIT ((uint64_t) 0xcbf29ce484222325ULL)
 
  /*
   * 64 bit Fowler/Noll/Vo FNV-1a hash code
   */
 static inline uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
 {
     unsigned char *bp = (unsigned char *) buf;
     unsigned char *be = bp + len;
     while (bp < be) {
         hval ^= (uint64_t) *bp++;
         hval += (hval << 1) + (hval << 4) + (hval << 5) +
             (hval << 7) + (hval << 8) + (hval << 40);
     }
     return hval;
 }
来自yaronspace.cn  本文链接:http://yaronspace.cn/blog/archives/1228