HashSet加载因子 [英] HashSet load factor

查看:273
本文介绍了HashSet加载因子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 HashSet ,初始容量为10,加载因子为0.5
,则每5个元素添加 HashSet 将会增加,或者首先 HashSet
增加10个元素,然后在15 at at 20 atc增加。容量会增加吗?

解决方案

负载系数衡量HashSet在容量增加之前的充足程度自动增加。当哈希表中的条目数超过加载因子和当前容量的乘积时,哈希表将被重新哈希(即,重建内部数据结构),以便哈希表具有大约两倍的桶数。 / p>

来源


If I use a HashSet with a initial capacity of 10 and a load factor of 0.5 then every 5 elements added the HashSet will be increased or first the HashSet is increased of 10 elements and after at 15 at 20 atc. the capacity will be increased?

解决方案

The load factor is a measure of how full the HashSet is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.

source

这篇关于HashSet加载因子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆