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 asFNV-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 =224 + 28 + 0x93 =
1677761964 bit FNV_prime = 240 + 28 + 0xb3 =
1099511628211128 bit FNV_prime = 288 + 28 + 0x3b =
309485009821345068724781371256 bit FNV_prime = 2168 + 28 + 0x63 =
374144419156711147060143317175368453031918731002211512 bit FNV_prime = 2344 + 28 + 0x57 =
35835915874844867368919076489095108449946327955754392558399825615420669938882575
1260940398923457138527591024 bit FNV_prime = 2680 + 28 + 0x8d =
50164565101131186554345988110352789550307653454047907443030175238311120551081474
51509157692220295382716162651878526895249385292291816524375083746691371804094271
873160484737966720260389217684476157468082573Part 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 =
100029257958052580907070968620625704837092796014241193945225284501741471925557512 bit offset_basis =
96593031294966694980094354007163104660904187456726378961083743294344626579945829
321977164384498130518922065398057844953282393400838761919287015838695177851024 bit offset_basis =
14197795064947621068722070641403218320880622795441933960878474914617582723252296
73230371772215086409652120235554936562817466910857181476047101507614802975596980
40773201576924585630032153049571501574036444603635505054127112859663616102678680
82893823963790439336411086884584107735010676915NOTE: 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!)
FNV与FNV-1a Hash算法说明【转】的更多相关文章
- hash算法总结收集
hash算法的意义在于提供了一种快速存取数据的方法,它用一种算法建立键值与真实值之间的对应关系,(每一个真实值只能有一个键值,但是一个键值可以对应多个真实值),这样可以快速在数组等条件中里面存取数据. ...
- MurmurHash算法:高运算性能,低碰撞率的hash算法
MurmurHash算法:高运算性能,低碰撞率,由Austin Appleby创建于2008年,现已应用到Hadoop.libstdc++.nginx.libmemcached等开源系统.2011年A ...
- 一致性hash算法简介与代码实现
一.简介: 一致性hash算法提出了在动态变化的Cache环境中,判定哈希算法好坏的四个定义: 1.平衡性(Balance) 2.单调性(Monotonicity) 3.分散性(Spread) 4.负 ...
- 常用的Hash算法
1.RSHash unsigned int RSHash(const std::string& str) { unsigned int b = 378551; unsigne ...
- 常见hash算法的原理
散列表,它是基于快速存取的角度设计的,也是一种典型的“空间换时间”的做法.顾名思义,该数据结构可以理解为一个线性表,但是其中的元素不是紧密排列的,而是可能存在空隙. 散列表(Hash table,也叫 ...
- 【数据结构与算法】一致性Hash算法及Java实践
追求极致才能突破极限 一.案例背景 1.1 系统简介 首先看一下系统架构,方便解释: 页面给用户展示的功能就是,可以查看任何一台机器的某些属性(以下简称系统信息). 消息流程是,页面发起请求查看指定机 ...
- Hash算法入门指南(聊点不一样的算法人生)
前言 很多人到现在为止都总是问我算法该怎么学啊,数据结构好难啊怎么的,学习难度被莫名的夸大了,其实不然.对于一个学计算机相关专业的人都知道,数据结构是大学的一门必修课,数据结构与算法是基础,却常常容易 ...
- 几种常用hash算法及原理
计算理论中,没有Hash函数的说法,只有单向函数的说法.所谓的单向函数,是一个复杂的定义,大家可以去看计算理论或者密码学方面的数据.用“人 类”的语言描述单向函数就是:如果某个函数在给定输入的时候,很 ...
- Hash算法的讲解
散列表,又叫哈希表,它是基于快速存取的角度设计的,也是一种典型的“空间换时间”的做法.顾名思义,该数据结构可以理解为一个线性表,但是其中的元素不是紧密排列的,而是可能存在空隙. 散列表(Hash ta ...
- Hash算法原理的简单分析
哈希计算就是努力的把比较大的数据存放到相对较小的空间中.最常见的哈希算法是取模法.下面简单讲讲取模法的计算过程.比如:数组的长度是5.这时有一个数据是6.那么如何把这个6存放到长度只有5的数组中呢.按 ...
随机推荐
- Virt-install用法:
#一般选项:指定虚拟机的名称.内存大小.VCPU个数及特性等 -n NAME, --name=NAME:虚拟机名称,需全局惟一: -r MEMORY, --ram=MEMORY:虚拟机内 ...
- [转载]matlab图像处理为什么要归一化和如何归一化
matlab图像处理为什么要归一化和如何归一化,一.为什么归一化1. 基本上归一化思想是利用图像的不变矩寻找一组参数使其能够消除其他变换函数对图像变换的影响.也就是转换成唯一的标准形式以抵抗仿射变 ...
- HTTP-常用配置
前言 这篇主要介绍HTTP服务程序环境 可能有一些介绍不到,博主能力有限,欢迎大神来纠正改进 HTTP协议从http/0.9到如今的http/2.0中间发生了很大的改变,现在主流的事http/1.1 ...
- PHP 代码优化建议
1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.当然了,这个测试方法需要在十万级以上次执行,效果才明显.其实静态方法和非静态方法的效率 ...
- PHP数组函数 array_multisort() ----对多个数组或多维数组进行排序
PHP中array_multisort可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序. 关联(string)键名保持不变,但数字键名会被重新索引. 输入数组被当成一个表的列并以 ...
- OOP之单例模式
- Python基础——异常
捕捉所有异常 for i in range(10): try: input_number=input('write a number') if input_number=='q': break res ...
- Aizu - 1378 Secret of Chocolate Poles (DP)
你有三种盘子,黑薄,白薄,黑厚. 薄的盘子占1,厚的盘子占k. 有一个高度为L的桶,盘子总高度不能超出桶的总高度(可以小于等于).相同颜色的盘子不能挨着放. 问桶内装盘子的方案数. 如 L = 5,k ...
- 并查集:POJ1182-食物链(并查集比较高端的应用)
食物链 Time Limit: 1000MS Memory Limit: 10000K Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C ...
- PAT Basic 1076
1076 Wifi密码 下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用 wifi,又怕耽误亲们的学习,现将 wifi 密码设置为下列数学题答案:A-1:B-2:C-3:D-4:请 ...