huangzworks / redis-3.0-annotated

带有详细注释的 Redis 3.0 代码(annotated Redis 3.0 source code)。
BSD 3-Clause "New" or "Revised" License
10.08k stars 4.23k forks source link

关于dictRehash的疑问 #26

Open zhugeliuyun opened 6 years ago

zhugeliuyun commented 6 years ago

while(de) { uint64_t h; nextde = de->next; / Get the index in the new hash table / h = dictHashKey(d, de->key) & d->ht[1].sizemask; de->next = d->ht[1].table[h]; d->ht[1].table[h] = de; d->ht[0].used--; d->ht[1].used++; de = nextde; } 以上代码是int dictRehash(dict *d, int n)中的部分实现,对于d->ht[0].used--有疑问,由于我们使用链接法解决冲突,所以de节点后面链接的所有节点理论上并没有记录在d->ht[0].used中,所以这里不是很明白,希望大神能帮我解惑。

Knight0xffff commented 4 years ago

https://github.com/huangz1990/redis-3.0-annotated/blob/unstable/src/dict.c#L492 https://github.com/huangz1990/redis-3.0-annotated/blob/unstable/src/dict.c#L559 每次增加节点时, 都会used++