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} 用工厂 ...
随机推荐
- Spring security OAuth2.0认证授权学习第四天(SpringBoot集成)
基础的授权其实只有两行代码就不单独写一个篇章了; 这两行就是上一章demo的权限判断; 集成SpringBoot SpringBoot介绍 这个篇章主要是讲SpringSecurity的,Spring ...
- 用Maven给一个Maven工程打包,使用阿里云镜像解决mvn clean package出错的问题,使用plugin解决没有主清单属性的问题
本来在STS里做了一个极简Maven工程,内中只有一个Main方法的Java类,然后用新装的Maven3.6.3给它打包. 结果,Maven罢工,输出如下: C:\personal\programs\ ...
- 仅显示sessionid,servername,serverport的一个springboot小程序
下载地址:https://files.cnblogs.com/files/xiandedanteng/sessionid20191227-1.zip --END-- 2019-12-2710:07
- pytest封神之路第二步 132个命令行参数用法
在Shell执行pytest -h可以看到pytest的命令行参数有这10大类,共132个 序号 类别 中文名 包含命令行参数数量 1 positional arguments 形参 1 2 gene ...
- datattable循环读取数据用于循环遍历checkboxlist里的项目
DataTable dt = bptb.GetList("Pro_ID="+id).Tables[0]; foreach (ListItem li in from DataRow ...
- python sha256 键值对参数格式接口测试
# coding=utf-8 import requests import time import uuid import hashlib import hmac import random impo ...
- 在腾讯云云函数计算上部署.NET Core 3.1
云厂商(腾讯云.Azure等)提供了Serverless服务,借助于Serverless,开发人员可以更加专注于代码的开发,减少运维的成本.腾讯云的函数计算提供了很多运行库,对.NET的支持需要通过c ...
- Traveling by Stagecoach(POJ 2686)
原题如下: Traveling by Stagecoach Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4494 Ac ...
- 详解usbmon抓取的log各字段的含义
详解 usbmon 抓取的 log 各字段的含义 在上篇文章中,我们已经介绍了如何在 linux 下使用 usbmon 抓取 usb 总线上数据的方法.(https://www.cnblogs.com ...
- vue | 基于vue的城市选择器和搜索城市对应的小区
城市选择器应该是比较常用的一个组件,用户可以去选择自己的城市,选择城市后返回,又根据自己选择的城市搜索小区. 功能展示 这是选择结果 这是选择城市 这是搜索小区 这是搜索小区接口,key为城市名字,i ...