php-5.6.26源代码 - hash存储结构 - hash算法
// zend_inline_hash_func 实现在文件“php-5.6.26\Zend\zend_hash.h”
h = zend_inline_hash_func(arKey, nKeyLength);
{
// zend_hash_add 定义在文件“php-5.6.26\Zend\zend_hash.h”
/*
* DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
*
* This is Daniel J. Bernstein's popular `times 33' hash function as
* posted by him years ago on comp.lang.c. It basically uses a function
* like ``hash(i) = hash(i-1) * 33 + str[i]''. This is one of the best
* known hash functions for strings. Because it is both computed very
* fast and distributes very well.
*
* The magic of number 33, i.e. why it works better than many other
* constants, prime or not, has never been adequately explained by
* anyone. So I try an explanation: if one experimentally tests all
* multipliers between 1 and 256 (as RSE did now) one detects that even
* numbers are not useable at all. The remaining 128 odd numbers
* (except for the number 1) work more or less all equally well. They
* all distribute in an acceptable way and this way fill a hash table
* with an average percent of approx. 86%.
*
* If one compares the Chi^2 values of the variants, the number 33 not
* even has the best value. But the number 33 and a few other equally
* good numbers like 17, 31, 63, 127 and 129 have nevertheless a great
* advantage to the remaining numbers in the large set of possible
* multipliers: their multiply operation can be replaced by a faster
* operation based on just one shift plus either a single addition
* or subtraction operation. And because a hash function has to both
* distribute good _and_ has to be very fast to compute, those few
* numbers should be preferred and seems to be the reason why Daniel J.
* Bernstein also preferred it.
*
*
* -- Ralf S. Engelschall <rse@engelschall.com>
*/ static inline ulong zend_inline_hash_func(const char *arKey, uint nKeyLength)
{
register ulong hash = ; /* variant with the hash unrolled eight times */
for (; nKeyLength >= ; nKeyLength -= ) {
hash = ((hash << ) + hash) + *arKey++;
hash = ((hash << ) + hash) + *arKey++;
hash = ((hash << ) + hash) + *arKey++;
hash = ((hash << ) + hash) + *arKey++;
hash = ((hash << ) + hash) + *arKey++;
hash = ((hash << ) + hash) + *arKey++;
hash = ((hash << ) + hash) + *arKey++;
hash = ((hash << ) + hash) + *arKey++;
}
switch (nKeyLength) {
case : hash = ((hash << ) + hash) + *arKey++; /* fallthrough... */
case : hash = ((hash << ) + hash) + *arKey++; /* fallthrough... */
case : hash = ((hash << ) + hash) + *arKey++; /* fallthrough... */
case : hash = ((hash << ) + hash) + *arKey++; /* fallthrough... */
case : hash = ((hash << ) + hash) + *arKey++; /* fallthrough... */
case : hash = ((hash << ) + hash) + *arKey++; /* fallthrough... */
case : hash = ((hash << ) + hash) + *arKey++; break;
case : break;
EMPTY_SWITCH_DEFAULT_CASE()
}
return hash;
}
}
php-5.6.26源代码 - hash存储结构 - hash算法的更多相关文章
- php-5.6.26源代码 - hash存储结构 - 添加
添加 , (void *)module, sizeof(zend_module_entry), (void**)&module_ptr){ // zend_hash_add 定义在文件“php ...
- php-5.6.26源代码 - hash存储结构 - 初始化
初始化 有指定析构函数,在销毁hash的时候会调用,如:“类似extension=test.so扩展”也是存放在HashTable中的,“类似extension=test.so扩展”的module_s ...
- Go redis hash存储结构体
需求 需要存储用户数据到redis,结构是hash. 然后取出来,自动转成结构体. 结构体 type UserCache struct { Id int64 `json:"id"` ...
- hash存储结构【六】
一.概述: 我们可以将Redis中的Hashes类型看成具有String Key和String Value的map容器.所以该类型非常适合于存储值对象的信息.如Username.Password和Ag ...
- Hash存储模型、B-Tree存储模型、LSM存储模型介绍
每一种数据存储系统,对应有一种存储模型,或者叫存储引擎.我们今天要介绍的是三种比较流行的存储模型,分别是: Hash存储模型 B-Tree存储模型 LSM存储模型 不同存储模型的应用情况 1.Hash ...
- Berkeley DB的数据存储结构——哈希表(Hash Table)、B树(BTree)、队列(Queue)、记录号(Recno)
Berkeley DB的数据存储结构 BDB支持四种数据存储结构及相应算法,官方称为访问方法(Access Method),分别是哈希表(Hash Table).B树(BTree).队列(Queue) ...
- Java提高篇——通过分析 JDK 源代码研究 Hash 存储机制
HashMap 和 HashSet 是 Java Collection Framework 的两个重要成员,其中 HashMap 是 Map 接口的常用实现类,HashSet 是 Set 接口的常用实 ...
- HashMap、HashSet源代码分析其 Hash 存储机制
集合和引用 就像引用类型的数组一样,当我们把 Java 对象放入数组之时,并不是真正的把 Java 对象放入数组中,只是把对象的引用放入数组中,每个数组元素都是一个引用变量. 实际上,HashSet ...
- 通过分析 JDK 源代码研究 Hash 存储机制
通过 HashMap.HashSet 的源代码分析其 Hash 存储机制 实际上,HashSet 和 HashMap 之间有很多相似之处,对于 HashSet 而言,系统采用 Hash 算法决定集合元 ...
随机推荐
- XUtils3 的 环境搭建与简单使用
XUtils3 的 环境搭建 环境搭建三部曲 ----------------------- 说明 : author 修雨轩陈 使用andorid Studio 已经创建了一个项目 并且自己需要使用 ...
- SpringBoot热部署插件
1.配置在 maven工程中的pom.xml文件中 2.SpringBoot框架中提供的一个热部署插件,利用该热部署插件,我们可以在修改代码后不用重启应用,大大提高开发效率:
- MSMQ学习笔记一——概述
一.MSMQ是什么 Message Queuing(MSMQ) 是微软开发的消息中间件,可应用于程序内部或程序之间的异步通信.主要的机制是:消息的发送者把自己想要发送的信息放入一个容器中(我们称之为M ...
- Ubuntu 下安装Mongodb
Mongodb是一款开源的数据库,这里不用我多说了,下面说一下Ubuntu下安装Mongodb可能遇到的问题和解决方案. 故事背景: 今天M$促销,1¥Windows Azure 4000¥-30天的 ...
- 再次拿起live writer
再次拿起live writer 第一次接触这哥们还是使用NPOI时,当时这个开源项目的发起人tonyqus让我知道了这家伙,感觉很不错,我们不需要直接用网页进行编辑内容,而且可以突破网页编辑器单调的设 ...
- ZJOI2019Day1镇海中学游记(3.24~3.27)
前言 第一次正式参加省选!不管怎么说,虽然明知自己很弱,但还是要尽力去尝试吧! 最好能进前\(100\),不然就没法去\(Day2\)了. \(Mar\ 24th\):出发 今天,我们正式从二中向宁波 ...
- 【[TJOI2017]城市】
题目 好像\(noip\)之前做某雅礼的题的时候看到过这道题的数据范围增强版 当时那道题数据范围是\(3e5\)感觉神仙的一批 这道题数据范围\(5e3\)那岂不是可以\(O(n^2)\)水过 有一点 ...
- PS中会使用到的快捷键有那些?
P.S:我刚刚在百度上,搜了一些关于PS的快捷键的使用. 我把它总结了一下.对我今后的P图有所帮助. PS的所有快捷键 1. 显示/隐藏选择区域 [Ctrl]+[H] 2. 取消当前命令:Esc: 工 ...
- 使用paramiko的问题记录
用paramiko时遇到问题,异常如下: 解决方法记录如下: 更新gmp版本: wget https://ftp.gnu.org/gnu/gmp/gmp-6.0.0a.tar.bz2 tar -xvj ...
- VI编辑器查找替换
1.Vi下进行查找 VI命令模式下:输入“/要查找的词”回车就会进入查找,你可以按“n”查找下一个,按“N”查找上一个.类似查找命令“?”与“/”的区别是“/”为向下查找,“?”为向上查找. 2.Vi ...