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} 用工厂 ...
随机推荐
- SpringBoot程序启动时在Oracle数据库中建表充值
例子工程下载链接:https://files.cnblogs.com/files/xiandedanteng/gatling20200428-1.zip 需求:在工程启动时在Oracle数据库中建表. ...
- AMQP 概论
AMQP 是应用层协议的一个开放标准,为面向消息的中间件设计.基于此协议的客户端与消息中间件可传递消息,并不受客户端/中间件不同产品,不同的开发语言等条件的限制.目标是实现一种在全行业广泛使用的标准消 ...
- 在腾讯云云函数计算上部署.NET Core 3.1
云厂商(腾讯云.Azure等)提供了Serverless服务,借助于Serverless,开发人员可以更加专注于代码的开发,减少运维的成本.腾讯云的函数计算提供了很多运行库,对.NET的支持需要通过c ...
- CSS 简介,学习 CSS 必看
CSS 表示的是层叠样式表,学习 CSS 之前我们必须要掌握 HTML 和 XHTML 概述 CSS 指层叠样式表 (Cascading Style Sheets) 样式定义如何显示 HTML 元素 ...
- docker下部署jira破解版
1. 制作Docker破解容器 在/opt/jira下新建一个Dockerfile文件 touch Dockerfile 编辑Dockerfile文件 vim Dockerfile FROM cpta ...
- mariadb 数据库集群配置
mariadb集群配置(主从和多主) mariadb主从 主从多用于网站架构,因为主从的同步机制是异步的,数据的同步有一定延迟,也就是说有可能会造成数据的丢失,但是性能比较好,因此网站大多数用的是 ...
- OKR工作法
OKR 目标与关键成果 [Objectives and Key Results] OKR是目标管理工具,它的价值不在于是否完成OKR,而在于呈现出团队最应该关注的事情,通过持续性的沟通确保每个人都聚焦 ...
- nginx中编写lua拦截器
先配置nginx location ~ .*\.(php|php5)?$ { if ($request_uri ~ "one/tes ...
- java Synchronized集合
在Collections存在相关"Synchronized"支持同步的集合, 在java1.0 也存在"Vector"; 为什么会选择放弃"Vecto ...
- selenium执行js--并绕过webdriver监测常见方法
目录 selenium执行js 常见的selenium监测手段 常用绕过selenium监测1 常用绕过selenium监测2 常用绕过selenium监测3 selenium执行js 优点:直接调用 ...