hash - 为什么redis dict中的load factor设置为1

标签 hash redis hashmap

众所周知,在哈希表中,负载因子对于控制冲突很重要。

In Java/HashMap, the default load factor is 0.75, And in CPython/dict, the load factor is set to 2 / 3

但是,在redis/dict中,是 1.0 (启用dict_can_resize时),为什么?

/* If we reached the 1:1 ratio, and we are allowed to resize the hash
 * table (global setting) or we should avoid it but the ratio between
 * elements/buckets is over the "safe" threshold, we resize doubling
 * the number of buckets. */
if (d->ht[0].used >= d->ht[0].size &&
    (dict_can_resize ||
     d->ht[0].used/d->ht[0].size > dict_force_resize_ratio))
{
    return dictExpand(d, d->ht[0].used*2);
}

在我看来,负载因子应该小于1。由于可能的高冲突率,高负载因子可能会增加查找成本。

最佳答案

高负载因子也能提高内存效率。 Redis 是一个内存数据库,它需要内存高效。我认为 Redis 的作者已经做了一些基准测试来平衡内存使用和性能。

关于hash - 为什么redis dict中的load factor设置为1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54810023/

相关文章:

asp.net - 在纯 T-SQL 中生成 ASP.Net 成员(member)密码哈希

bcrypt 的.Net 实现,它实现了HashAlgorithm?

mysql - 使用大量队列工作人员时如何避免大量连接?

php - PHP 和 Node.js 的 FIFO 共享存储

server - 为什么我的 redis 服务器不活动 - Ubuntu 16.04

java - 为什么我的 HashMap.get 即使在输入正确的键、值后仍返回空值?

python - Spark 对 HashingTF 使用什么哈希函数以及如何复制它?

C++ - 为什么 boost::hash_combine 是组合散列值的最佳方式?

java - 为什么我们在向firestore发送数据时,将HashMap中的参数设置为object?

Java HashMap 到矩阵