你的位置:首页 > 软件开发 > 数据库 > redis数据结构存储Dict设计细节(redis的设计与实现笔记)

redis数据结构存储Dict设计细节(redis的设计与实现笔记)

发布时间:2016-12-11 12:00:09
说到redis的Dict(字典),虽说算法上跟市面上一般的Dict实现没有什么区别,但是redis的Dict有2个特殊的地方那就是它的rehash(重新散列)和它的字典节点单向链表。以下是dict用到的结构:typedef struct dictEntry {//字典的节点 ...

redis数据结构存储Dict设计细节(redis的设计与实现笔记)

说到redis的Dict(字典),虽说算法上跟市面上一般的Dict实现没有什么区别,但是redis的Dict有2个特殊的地方那就是它的rehash(重新散列)和它的字典节点单向链表。

以下是dict用到的结构:

typedef struct dictEntry {//字典的节点   void *key;   union {//使用的联合体     void *val;     uint64_t u64;//这两个参数很有用     int64_t s64;   } v;   struct dictEntry *next;//下一个节点指针 } dictEntry;  typedef struct dictType {   unsigned int (*hashFunction)(const void *key); //hash函数指针   void *(*keyDup)(void *privdata, const void *key); //键复制函数指针   void *(*valDup)(void *privdata, const void *obj); //值复制函数指针   int (*keyCompare)(void *privdata, const void *key1, const void *key2); //键比较函数指针   void (*keyDestructor)(void *privdata, void *key); //键构造函数指针   void (*valDestructor)(void *privdata, void *obj); //值构造函数指针 } dictType;  /* This is our hash table structure. Every dictionary has two of this as we * implement incremental rehashing, for the old to the new table. */ typedef struct dictht { //字典hash table   dictEntry **table;//可以看做字典数组,俗称桶bucket   unsigned long size; //指针数组的大小,即桶的层数   unsigned long sizemask;   unsigned long used; //字典中当前的节点数目 } dictht;  typedef struct dict {   dictType *type;   void *privdata; //私有数据   dictht ht[2];  //两个hash table   int rehashidx; /* rehashing not in progress if rehashidx == -1 */ //rehash 索引   int iterators; /* number of iterators currently running */ //当前该字典迭代器个数 } dict;  

原标题:redis数据结构存储Dict设计细节(redis的设计与实现笔记)

关键词:Redis

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录