转自: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 =
    16777619

    64 bit FNV_prime = 240 + 28 + 0xb3 =
    1099511628211

    128 bit FNV_prime = 288 + 28 + 0x3b =
    309485009821345068724781371

    256 bit FNV_prime = 2168 + 28 + 0x63 =
    374144419156711147060143317175368453031918731002211

    512 bit FNV_prime = 2344 + 28 + 0x57 =

    35835915874844867368919076489095108449946327955754392558399825615420669938882575
    126094039892345713852759

    1024 bit FNV_prime = 2680 + 28 + 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!)

FNV与FNV-1a Hash算法说明【转】的更多相关文章

  1. hash算法总结收集

    hash算法的意义在于提供了一种快速存取数据的方法,它用一种算法建立键值与真实值之间的对应关系,(每一个真实值只能有一个键值,但是一个键值可以对应多个真实值),这样可以快速在数组等条件中里面存取数据. ...

  2. MurmurHash算法:高运算性能,低碰撞率的hash算法

    MurmurHash算法:高运算性能,低碰撞率,由Austin Appleby创建于2008年,现已应用到Hadoop.libstdc++.nginx.libmemcached等开源系统.2011年A ...

  3. 一致性hash算法简介与代码实现

    一.简介: 一致性hash算法提出了在动态变化的Cache环境中,判定哈希算法好坏的四个定义: 1.平衡性(Balance) 2.单调性(Monotonicity) 3.分散性(Spread) 4.负 ...

  4. 常用的Hash算法

    1.RSHash unsigned int RSHash(const std::string& str) {    unsigned int b    = 378551;    unsigne ...

  5. 常见hash算法的原理

    散列表,它是基于快速存取的角度设计的,也是一种典型的“空间换时间”的做法.顾名思义,该数据结构可以理解为一个线性表,但是其中的元素不是紧密排列的,而是可能存在空隙. 散列表(Hash table,也叫 ...

  6. 【数据结构与算法】一致性Hash算法及Java实践

    追求极致才能突破极限 一.案例背景 1.1 系统简介 首先看一下系统架构,方便解释: 页面给用户展示的功能就是,可以查看任何一台机器的某些属性(以下简称系统信息). 消息流程是,页面发起请求查看指定机 ...

  7. Hash算法入门指南(聊点不一样的算法人生)

    前言 很多人到现在为止都总是问我算法该怎么学啊,数据结构好难啊怎么的,学习难度被莫名的夸大了,其实不然.对于一个学计算机相关专业的人都知道,数据结构是大学的一门必修课,数据结构与算法是基础,却常常容易 ...

  8. 几种常用hash算法及原理

    计算理论中,没有Hash函数的说法,只有单向函数的说法.所谓的单向函数,是一个复杂的定义,大家可以去看计算理论或者密码学方面的数据.用“人 类”的语言描述单向函数就是:如果某个函数在给定输入的时候,很 ...

  9. Hash算法的讲解

    散列表,又叫哈希表,它是基于快速存取的角度设计的,也是一种典型的“空间换时间”的做法.顾名思义,该数据结构可以理解为一个线性表,但是其中的元素不是紧密排列的,而是可能存在空隙. 散列表(Hash ta ...

  10. Hash算法原理的简单分析

    哈希计算就是努力的把比较大的数据存放到相对较小的空间中.最常见的哈希算法是取模法.下面简单讲讲取模法的计算过程.比如:数组的长度是5.这时有一个数据是6.那么如何把这个6存放到长度只有5的数组中呢.按 ...

随机推荐

  1. Xcode开发技巧

    1.Xcode 中的 Code Snippets 默认放在下面的目录中: ~/Library/Developer/Xcode/UserData/CodeSnippets 2.自定义的代码背景颜色和代码 ...

  2. Leetcode 20 有效的括号valid-parentheses(栈)

    给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被认 ...

  3. [CF] 180 E. Cubes

    对同类元素双指针扫描 #include<iostream> #include<cstring> #include<cstdio> #include<vecto ...

  4. 【Python学习之六】高阶函数2(map、reduce、filter、sorted)

    3.filter filter()也接收一个函数和一个序列.和map()不同的是,filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素.相当于一 ...

  5. ubuntu下RedisDesktopManager的安装,redis可视化工具

    官方网站:https://redisdesktop.com/download 一句命令行解决: sudo snap install redis-desktop-manager 或者直接通过软件管理中心 ...

  6. 示例vue 的keep-alive缓存功能的实现

    本篇文章主要介绍了vue 的keep-alive缓存功能的实现,写的十分的全面细致,具有一定的参考价值,对此有需要的朋友可以参考学习下.如有不足之处,欢迎批评指正. Vue 实现组件信息的缓存 当我们 ...

  7. 【linux】 服务器文件说明

    文件名 说明 /etc/resolv.conf  域名解析服务器地址文件 /etc/services 服务程序对应端口号文件 /etc/passwd 登录账号文件 /etc/hosts 本地IP域名解 ...

  8. django知识分支_1

    django知识分支 1.Cookie工作流程: 浏览器向服务器发出请求,服务器接收到浏览器的请求进行处理,服务器设置一个cookie发送给浏览器,浏览器将cookie保存,当需要再次登录的时候,浏览 ...

  9. Java-framework-Vaadin

    安装vaadin: (1) 首先试了maven+vaadin. 安装maven: 1. unzip apache-maven-3.3.9-bin.zip 2. modify PATH environm ...

  10. 【HIHOCODER 1599】逃离迷宫4

    描述 小Hi被坏女巫抓进一座由无限多个格子组成的矩阵迷宫. 小Hi一开始处于迷宫(x, y)的位置,迷宫的出口在(a, b).小Hi发现迷宫被女巫施加了魔法,假设当前他处在(x, y)的位置,那么他只 ...