
最近在阅读redis源代码,决定将自己的一些理解记下来,用于备份和检查。无奈技术水平很挫,如果有错误,还希望指正。代码版本是2.6.2,代码量比2.4.17大了很多。==!
- typedef struct dictht {
- dictEntry **table;
- unsigned long size; //hash表的大小(总为2的n次幂)
- unsigned long sizemask; //实际为size - 1,这样就可以直接对sizemask进行取模获得桶的位置
- unsigned long used; //hash表中已经使用的桶数
- } dictht;
- typedef struct dict {
- dictType *type;
- void *privdata;
- dictht ht[2];//有两个hash表,一开始新增加的元素都会塞到ht[0]中去,当负载因子(元素数目/桶数)达到一定的阈值(dict_force_resize_ratio = 5),就会扩容
- int rehashidx; /* rehashing not in progress if rehashidx == -1 */
- int iterators; /* number of iterators currently running ,redis限制有迭代器(iterators > 0)的时候,禁止rehash*/
- } dict;
173万+

被折叠的 条评论
为什么被折叠?



