FNV与FNV-1a Hash算法说明【转】

简介:

转自:http://blog.csdn.net/jiayanhui2877/article/details/12090575

The core of the FNV hash

The core of the  FNV-1  hash algorithm is as follows:
hash = offset_basis
for each octet_of_data to be hashed
 hash = hash * FNV_prime
 hash = hash xor octet_of_data
return 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  FNV  hash algorithm known as FNV-1a :
hash = offset_basis
for each octet_of_data to be hashed
 hash = hash xor octet_of_data
 hash = hash * FNV_prime
return hash

The only difference between the FNV-1a hash and the FNV-1 hashis the order of the xor and multiply.The 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-1  hash parameters are as follows:
  • hash is an n bit unsigned integer,where n is the bit length of hash.
  • The multiplication is performed modulo 2nwhere n is the bit length of hash.
  • The xor is performed on the low orderoctet (8 bits) of hash.
  • The FNV_prime is dependent on n, the size of the hash:
    32 bit  FNV_prime =2 24 + 2 8 + 0x93 = 16777619

    64 bit  FNV_prime = 2 40 + 2 8 + 0xb3 = 1099511628211

    128 bit  FNV_prime = 2 88 + 2 8 + 0x3b = 309485009821345068724781371

    256 bit  FNV_prime = 2 168 + 2 8 + 0x63 = 374144419156711147060143317175368453031918731002211

    512 bit  FNV_prime = 2 344 + 2 8 + 0x57 = 
    35835915874844867368919076489095108449946327955754392558399825615420669938882575
    126094039892345713852759

    1024 bit  FNV_prime = 2 680 + 2 8 + 0x8d = 
    50164565101131186554345988110352789550307653454047907443030175238311120551081474
    51509157692220295382716162651878526895249385292291816524375083746691371804094271
    873160484737966720260389217684476157468082573

    Part of the magic of FNV is the selection of the FNV_primefor a given sized unsigned integer.Some primes do hash better than other primes for a given integer size.

  • The offset_basis for FNV-1 is dependent on n, the size of the hash:
    32 bit  offset_basis = 2166136261

    64 bit  offset_basis = 14695981039346656037

    128 bit  offset_basis = 144066263297769815596495629667062367629

    256 bit  offset_basis = 
    100029257958052580907070968620625704837092796014241193945225284501741471925557

    512 bit  offset_basis = 
    96593031294966694980094354007163104660904187456726378961083743294344626579945829
    32197716438449813051892206539805784495328239340083876191928701583869517785

    1024 bit  offset_basis = 
    14197795064947621068722070641403218320880622795441933960878474914617582723252296
    73230371772215086409652120235554936562817466910857181476047101507614802975596980
    40773201576924585630032153049571501574036444603635505054127112859663616102678680
    82893823963790439336411086884584107735010676915

    NOTE: Older versions of this web page incorretly indicated that the 128 bitFNV_prime was 2168 + 28 + 0x59.This was not correct.While that satisfied all of the significant FNV_prime properties,it was not the smallest 128 bit FNV_prime.The 128 bit offset_basischanged from275519064689413815358837431229664493455to144066263297769815596495629667062367629was changed as a result of the 128 bit FNV_prime correction.(Sorry about that!)









本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/6478167.html ,如需转载请自行联系原作者
相关文章
|
存储 缓存 负载均衡
一致性 Hash 算法 Hash 环发生偏移怎么解决
一致性 Hash 算法 Hash 环发生偏移怎么解决
252 1
|
3月前
|
存储 负载均衡 算法
我们来说一说 Java 的一致性 Hash 算法
我是小假 期待与你的下一次相遇 ~
109 1
|
算法 Java
Java中常用hash算法总结
Java中常用hash算法总结
190 0
|
算法 数据可视化 数据处理
Algorithms_算法专项_Hash算法的原理&哈希冲突的解决办法
Algorithms_算法专项_Hash算法的原理&哈希冲突的解决办法
148 0
|
存储 算法 索引
Python 数据结构和算法:什么是散列表(Hash Table)?在 Python 中如何实现?
Python 数据结构和算法:什么是散列表(Hash Table)?在 Python 中如何实现?
143 0
|
9天前
|
存储 编解码 算法
【多光谱滤波器阵列设计的最优球体填充】使用MSFA设计方法进行各种重建算法时,图像质量可以提高至多2 dB,并在光谱相似性方面实现了显著提升(Matlab代码实现)
【多光谱滤波器阵列设计的最优球体填充】使用MSFA设计方法进行各种重建算法时,图像质量可以提高至多2 dB,并在光谱相似性方面实现了显著提升(Matlab代码实现)
|
11天前
|
传感器 机器学习/深度学习 算法
【使用 DSP 滤波器加速速度和位移】使用信号处理算法过滤加速度数据并将其转换为速度和位移研究(Matlab代码实现)
【使用 DSP 滤波器加速速度和位移】使用信号处理算法过滤加速度数据并将其转换为速度和位移研究(Matlab代码实现)
|
10天前
|
传感器 机器学习/深度学习 算法
【UASNs、AUV】无人机自主水下传感网络中遗传算法的路径规划问题研究(Matlab代码实现)
【UASNs、AUV】无人机自主水下传感网络中遗传算法的路径规划问题研究(Matlab代码实现)
|
9天前
|
机器学习/深度学习 传感器 算法
【高创新】基于优化的自适应差分导纳算法的改进最大功率点跟踪研究(Matlab代码实现)
【高创新】基于优化的自适应差分导纳算法的改进最大功率点跟踪研究(Matlab代码实现)
91 14
|
9天前
|
机器学习/深度学习 运维 算法
【微电网多目标优化调度】多目标学习者行为优化算法MOLPB求解微电网多目标优化调度研究(Matlab代码实现)
【微电网多目标优化调度】多目标学习者行为优化算法MOLPB求解微电网多目标优化调度研究(Matlab代码实现)

热门文章

最新文章