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的更多相关文章

  1. Redis 支持的5种数据结构

    redis的崛起绝非偶然,它确实有自己的新东西在里面,它不像Memcached,只能将数据存储在内存中,它提供了持久化机制和数据同步,避免了宕机后的雪崩的问题,即服务器出现问题后,内存中保留的原始数据 ...

  2. 小表驱动大表, 兼论exists和in

    给出两个表,A和B,A和B表的数据量, 当A小于B时,用exists select * from A where exists (select * from B where A.id=B.id) ex ...

  3. Redis的五种数据结构

    Redis支持持久化只是它的一件武器,它提供了多达5种数据存储方式: 一  string(字符串) string是最简单的类型,你可以理解成与Memcached一模一样的类型,一个key对应一个val ...

  4. redis’五种格式的存储与展示

    Redis支持持久化只是它的一件武器,另外,它针对不同的需求也提供了多达5种数据存储方式,以最大效率上的实现你的需求,下面分别说一下: 一  string(字符串) string是最简单的类型,你可以 ...

  5. Redis、Memcache和MongoDB的区别

    >>Memcached Memcached的优点:Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS(取决于key.value的字节大小以及服务器硬件性能,日常环境 ...

  6. redis、memcache、mongoDB有哪些区别(转载)

    转载: http://leandre.cn/database/64.html Memcached Memcached的优点: Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS ...

  7. Redis指令文档

    连接控制QUIT 关闭连接AUTH (仅限启用时)简单的密码验证 适合全体类型的命令EXISTS key 判断一个键是否存在;存在返回 1;否则返回0;DEL key 删除某个key,或是一系列key ...

  8. 什么是redis数据库?

    新公司的第一个项目让用redis.之前没接触过,所以从网上找些文章,学习理解一下   原链接:http://baike.so.com/doc/5063975-5291322.html 什么是redis ...

  9. Python核心编程读笔 6: 映射和集合类型

    第七章 映射和集合能力 一 字典(python中唯一的映射类型) 1 基本 创建和赋值: 正常创建:>>>dict = {'name':'earth', 'port':80} 用工厂 ...

随机推荐

  1. Selenium文件上传问题

     

  2. UEFI、BIOS、GPT、MBR等概念的辨析

    (本文转移自本人的旧博客) 从各个地方包括知乎,Wiki,CSDN搜索到的一些整理,这些概念极易混淆. 先说互相的关系 BIOS和UEFI是两种固件接口标准 MBR和GPT是两种分区表 Legacy模 ...

  3. Native Comments

    local variables referenced from a Lambda expression must be final or effectively final. Lambda表达式中引用 ...

  4. 20190923-09Linux磁盘分区类 000 017

    df 查看磁盘空间使用情况 df: disk free 空余硬盘 1.基本语法 df  选项 (功能描述:列出文件系统的整体磁盘使用量,检查文件系统的磁盘空间占用情况) 2.选项说明 表1-32 选项 ...

  5. [业界方案]用Jaeger来学习分布式追踪系统Opentracing

    [业界方案]用Jaeger来学习分布式追踪系统Opentracing 目录 [业界方案]用Jaeger来学习分布式追踪系统Opentracing 0x00 摘要 0x01 缘由 & 问题 1. ...

  6. pytest测试框架 -- 简介

    一.pytest测试框架简介: (1)pytest是python的第三方测试框架,是基于unittest的扩展框架,比unittest更简洁,更高效. (2)pytest框架可以兼容unittest用 ...

  7. python模块之----subprocess

    例子 >>> subprocess.getstatusoutput('pwd')(0, '/home/ronny')>>> subprocess.getoutput ...

  8. [极客大挑战 2019]Secret File wp

    通过标题考虑可能为文件包含漏洞方面 打开网页 从页面并没任何思路,查看源代码 得到有一个跳转到./Archive_room.php的超链接,打开Archive_room.php 中央有一个secret ...

  9. Java并发包之Executors

    概述 Executor.ExecutorService.ScheduledExecutorService.ThreadFactory.Callable的工厂和工具类. 方法 构造一个固定线程数目的线程 ...

  10. 搜索引擎学习(六)Query的子类查询

    Query的子类查询 PS:这是通用代码,下面的子类查询调用到的时候就不再写这部分的具体的实现过程了 /** * 构造IndexSearcher对象 * * @return * @throws Exc ...