Transferred from: http://blog.csdn.net/jiayanhui2877/article/details/12090575
The core of the FNV hash
The core of the
FNV-1Hash algorithm is as Follows:
Hash offset_basis Octet_of_data Hash Hash fnv_prime Hash Hash Octet_of_data Hash
The offset_basis andfnv_prime can be found in theparameters of the FNV-1/FNV-1A hash section below.
FNV-1A Alternate algorithm There is a minor variation of the
FNVHash algorithm known as
fnv-1a:
Hash offset_basis Octet_of_data Hash Hash Octet_of_data Hash Hash Fnv_prime Hash
The only difference between the fnv-1a hash and the FNV-1 hashis The order of the XOR and multiply.t He fnv-1a hashuses the same fnv_prime and offset_basisas the FNV-1 hash of the Same n-bit size.
Parameters of the FNV-1/FNV-1A hash The
FNV-1Hash parameters is as Follows:
- Hash is a n bit unsigned integer,where n is the bit length of hash.
- The multiplication is performed modulo 2nwhere n is the bit length of the hash.
- The XOR is performed on the low orderoctet (8 bits) of the hash.
- TheFnv_primeis dependent onN, the size of the Hash:
+ bit
fnv_prime =224 + + 0x93 = 16777619
fnv_prime = + + + 0xb3 = 1099511628211
-bit
fnv_prime = 288 + 0x3b = 309485009821345068724781371
[bit]
fnv_prime = 2168 + + 0x63 = 374144419156711147060143317175368453031918731002211
A bit FNV _prime = 2344 + 0x57 =
35835915874844867368919076489095108449946327955754392558399825615420669938882575
126094039892345713852759
1024x768 bit fnv_prime = 2680 + + 0x8d =
5016456510113118655434598811 0352789550307653454047907443030175238311120551081474
51509157692220295382716162651878526895249385292291816524375083746691371804094271
873160484737966720260389217684476157468082573
Part of the The magic of FNV are the selection of the Fnv_primefor a given sized unsigned integer. Some primes do hash better than other primes for a given integer size.
- Theoffset_basisForFNV-1is dependent onN, the size of the Hash:
+ bit
offset_basis= 2166136261
A bit
offset_basis= 14695981039346656037
-bit
offset_basis= 144066263297769815596495629667062367629
Bit
offset_basis=
100029257958052580907070968620625704837092796014241193945225284501741471925557
A bit
offset_basis=
96593031294966694980094354007163104660904187456726378961083743294344626579945829
32197716438449813051892206539805784495328239340083876191928701583869517785
1024x768 bit
offset_basis=
14197795064947621068722070641403218320880622795441933960878474914617582723252296
73230371772215086409652120235554936562817466910857181476047101507614802975596980
40773201576924585630032153049571501574036444603635505054127112859663616102678680
82893823963790439336411086884584107735010676915
Note:older versions of this web page incorretly indicated that the-bitfnv_prime was 2168 + + 0x59. This is not correct. While this satisfied all of the significantfnv_prime Properties,it is not the smallest-bit fnv_prime. The offset_basischanged from 275519064689413815358837431229664493455 to 144066263297769815596495629667062367629was changed as a result of the bitfnv_prime Correction. (Sorry about That!)
FNV and fnv-1a hash Algorithm description "go"