redis hashTable实现细节(1)
来源:互联网 发布:java void 方法 编辑:程序博客网 时间:2024/05/17 08:39
1.h为哈希值,下面这行代码是为key分配在hashtable的索引,即位置
idx = h & d->ht[table].sizemask;
2哈希表扩容
/* Expand or create the hash table */
int dictExpand(dict *d, unsigned long size)
{
dictht n; /* the new hash table */
unsigned long realsize = _dictNextPower(size);
/* the size is invalid if it is smaller than the number of
* elements already inside the hash table */
if (dictIsRehashing(d) || d->ht[0].used > size)
return DICT_ERR;
/* Allocate the new hash table and initialize all pointers to NULL */
n.size = realsize;
n.sizemask = realsize-1;
n.table = zcalloc(realsize*sizeof(dictEntry*));
n.used = 0;
/* Is this the first initialization? If so it's not really a rehashing
* we just set the first hash table so that it can accept keys. */
if (d->ht[0].table == NULL) {
d->ht[0] = n;
return DICT_OK;
}
/* Prepare a second hash table for incremental rehashing */
d->ht[1] = n;
d->rehashidx = 0;
return DICT_OK;
}
static unsigned long _dictNextPower(unsigned long size)
{
unsigned long i = DICT_HT_INITIAL_SIZE;
if (size >= LONG_MAX) return LONG_MAX;
while(1) {
if (i >= size)
return i;
i *= 2;
}
}
http://www.hoterran.info/redis_dict
- redis hashTable实现细节(1)
- Redis Cluster 实现细节
- Java集合类Hashtable实现细节
- Redis基础结构之hashtable(字典实现)
- redis, dict, hashtable
- redis 中的hashtable
- HashTable实现
- HashTable实现
- HashTable实现
- 实现HashTable
- 《Redis设计与实现》阅读:Redis底层研究之哈希表hashtable
- hashtable实现 -- 参考leveldb hashtable
- redis数据结构存储SDS设计细节(redis的设计与实现笔记)
- Redis命令小细节
- HashTable实现 中
- javascript 实现hashtable集合
- Hashtable(完整实现)
- HashTable实现一
- 网站外链登陆无忧管理器
- 魔咒词典
- JQuery从后台获取数据绑定到HTML标签select
- YUV420转YUV444 , YUV420转RGB .
- 使用perl创建Excel表格统计数据
- redis hashTable实现细节(1)
- Flex里的fx、mx和s命名空间
- 斗地主算法逻辑中的天之道
- CentOS中安装gcc编译器
- nginx aio机制详解
- 通过端口 1433 连接到主机 127.0.0.1 的 TCP/IP 连接失败。错误:“connect timed out。"
- MySpace架构演进
- c#调用c++的ocx控件传递数组
- 消息中间件的比较-转载