dict, hash
dict:
dictKey -- > dictVal
example:
dictEntry *dictFind(dict *d, const void *key)
Key is like a index which to find the real entry.
how to find:
depend on the construction of dict.
if dict is constructed by arr then we get arr[i]. key is not integer usual and here the array is a map.
if dict is constructed by hash table, then we get hash table value.
redis code dictFind:
typedef struct dict {
dictType *type;
void *privdata;
dictht ht[2];
long rehashidx; /* rehashing not in progress if rehashidx == -1 */
int iterators; /* number of iterators currently running */
} dict;
typedef struct dictht {
dictEntry **table;
unsigned long size;
unsigned long sizemask;
unsigned long used;
} dictht;
dictEntry *dictFind(dict *d, const void *key)
{
dictEntry *he;
unsigned int h, idx, table; if (d->ht[0].size == 0) return NULL; /* We don't have a table at all */
if (dictIsRehashing(d)) _dictRehashStep(d);
h = dictHashKey(d, key);
for (table = 0; table <= 1; table++) {
idx = h & d->ht[table].sizemask;
he = d->ht[table].table[idx];
while(he) {
if (dictCompareKeys(d, key, he->key))
return he;
he = he->next;
}
if (!dictIsRehashing(d)) return NULL;
}
return NULL;
}
key -> hashValue -> &hashMask -> hashIndex -> hashTable[hashIndex] (hashTableEleList[idx]) -> hashTableEleList[idx][j]
dictKey ----------------------------------------------------------------------------------------------------------------------> dictVal
why hash:

no hash table , store m * n elems.
hash, store m list head.
seraching, storing...
比如 dict 是个管理仓库的,仓库管理员按客人的姓名笔划来分架子。李一一来取货,dict算下李的在8号架子上,但是是8号架上的哪个柜子,要一个个来查看,只能根据姓名来一一对比了,最终找到客人的柜子,那个大的东西,肯定不好拿了,直接告诉李一一你的柜子地址就好了,让李一一去自己去对这个柜子中的东西操作。
dict, hash的更多相关文章
- Redis 支持的5种数据结构
redis的崛起绝非偶然,它确实有自己的新东西在里面,它不像Memcached,只能将数据存储在内存中,它提供了持久化机制和数据同步,避免了宕机后的雪崩的问题,即服务器出现问题后,内存中保留的原始数据 ...
- 小表驱动大表, 兼论exists和in
给出两个表,A和B,A和B表的数据量, 当A小于B时,用exists select * from A where exists (select * from B where A.id=B.id) ex ...
- Redis的五种数据结构
Redis支持持久化只是它的一件武器,它提供了多达5种数据存储方式: 一 string(字符串) string是最简单的类型,你可以理解成与Memcached一模一样的类型,一个key对应一个val ...
- redis’五种格式的存储与展示
Redis支持持久化只是它的一件武器,另外,它针对不同的需求也提供了多达5种数据存储方式,以最大效率上的实现你的需求,下面分别说一下: 一 string(字符串) string是最简单的类型,你可以 ...
- Redis、Memcache和MongoDB的区别
>>Memcached Memcached的优点:Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS(取决于key.value的字节大小以及服务器硬件性能,日常环境 ...
- redis、memcache、mongoDB有哪些区别(转载)
转载: http://leandre.cn/database/64.html Memcached Memcached的优点: Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS ...
- Redis指令文档
连接控制QUIT 关闭连接AUTH (仅限启用时)简单的密码验证 适合全体类型的命令EXISTS key 判断一个键是否存在;存在返回 1;否则返回0;DEL key 删除某个key,或是一系列key ...
- 什么是redis数据库?
新公司的第一个项目让用redis.之前没接触过,所以从网上找些文章,学习理解一下 原链接:http://baike.so.com/doc/5063975-5291322.html 什么是redis ...
- Python核心编程读笔 6: 映射和集合类型
第七章 映射和集合能力 一 字典(python中唯一的映射类型) 1 基本 创建和赋值: 正常创建:>>>dict = {'name':'earth', 'port':80} 用工厂 ...
随机推荐
- Zabbix icmp pinger processes more than 75% busy
Zabbix icmp pinger processes more than 75% busy Zabbix server报"Zabbix icmp pinger processes m ...
- HKDAS产品技术架构图
- jni之jni与jna的比较
java开发过程中会遇到需要调用c/c++动态库(windows平台的dll和linux平台的so)的情况,可以使用JNI或者JNA技术. JNA基于JNI技术开发,主要在上层作了类型自动转换的封装, ...
- python中绝对值的表达式
abs(x) print(abs(23)) #23print(abs(-45)) #45
- 吴恩达《深度学习》-第一门课 (Neural Networks and Deep Learning)-第四周:深层神经网络(Deep Neural Networks)-课程笔记
第四周:深层神经网络(Deep Neural Networks) 4.1 深层神经网络(Deep L-layer neural network) 有一些函数,只有非常深的神经网络能学会,而更浅的模型则 ...
- [LeetCode]230. 二叉搜索树中第K小的元素(BST)(中序遍历)、530. 二叉搜索树的最小绝对差(BST)(中序遍历)
题目230. 二叉搜索树中第K小的元素 给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素. 题解 中序遍历BST,得到有序序列,返回有序序列的k-1号元素. 代 ...
- StarUML 3.1.0 for Windows 10
StarUML 3.1.0 for Windows 10 1.下载 StarUML 3.1.0 http://staruml.io/download 2.安装 npm 到官网下载安装 windows版 ...
- maximo入门----用户使用提要
其实七月初就知道自己要做maximo了,但是那个时候
- spring boot 源码之banner
Banner 使用Spring Boot启动的jar包总是会显示一个Spring的图标.实际我们是可以自定义这个图标.Banner接口定义了打印banner的方法. void printBanner( ...
- kafka学习(四)kafka安装与命令行调用
文章更新时间:2020/06/07 一.安装JDK 过程就不过多介绍了... 二.安装Zookeeper 安装过程可以参考此处~ 三.安装并配置kafka Kafka下载地址 http://kafk ...