FNV-1a Hash 算法代码实例


  1 #include "stdio.h"
  2 #include "string.h"
  3
  4 unsigned int FNV_Hash(unsigned int uiSrcData)
  5 {
  6     /* FNV_prime = 224 + 28 + 0x93 = 16777619
  7         32 bit offset_basis = 2166136261
  8     */
  9
 10     unsigned int offset_basis = 2166136261;
 11     unsigned int FNV_prime = 16777619;
 12     unsigned int hash;
 13
 14     hash = offset_basis;
 15
 16     //for each octet_of_data to be hashed
 17      hash = hash ^ uiSrcData;
 18      hash = hash * FNV_prime;
 19      return hash;
 20 }
 21
 22 int main()
 23 {
 24     unsigned int i = 0x34567890;
 25     unsigned int j = 0x89078656;
 26
 27     printf("hasn(i) is %ld\n",FNV_Hash(i) & 65535);
 28     printf("hasn(j) is %ld\n",FNV_Hash(j) & 65535);
 29
 30 }

你可能感兴趣的:(FNV-1a Hash 算法代码实例)