读REDIS数据结构

一.DICT

主要有两个问题:

1.散列冲突,解决办法是拉链法

typedef struct dictEntry {
    void *key;
    union {
        void *val;
        uint64_t u64;
        int64_t s64;
    } v;
    struct dictEntry *next;
} dictEntry;

next字段向后拉链

2.扩容时候的rehash,做类似于copy on write

typedef struct dict {
    dictType *type;
    void *privdata;
    dictht ht[2];
    int rehashidx; /* rehashing not in progress if rehashidx == -1 */
    int iterators; /* number of iterators currently running */
} dict;

ht[0] 是存储了没扩容时候的数据,ht[1]存储扩容以后的数据。如果在需要扩容的时候,任何对哈希表的操作都会从ht[0]中找到一个key rehash以后放到ht[1],逐渐把ht[0]中的数据放到ht[1],当ht[0]中全部rehash完以后,释放空间,ht[0]指向ht[1]。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值