gpt4 book ai didi

java - 为什么 Hashtable 中有这么多空引用

转载 作者:行者123 更新时间:2023-12-02 11:33:31 32 4
gpt4 key购买 nike

enter image description here

我试图调试 Hashtable 内容,并很好奇为什么 init 中有这么多 Null 引用。

最佳答案

这就是哈希表的工作原理。 For reference

In computing, a hash table (hash map) is a data structure whichimplements an associative array abstract data type, a structure thatcan map keys to values. A hash table uses a hash function to computean index into an array of buckets or slots, from which the desiredvalue can be found.

存储桶的数量通常多于值的数量,这就是为什么有些存储桶是空的。

这对于哈希表的性能很重要。

A critical statistic for a hash table is the load factor, defined as

load_factor=n/k

where n is the number of entries occupied in the hash table. k is the numberof buckets. As the load factor grows larger, the hash table becomesslower, and it may even fail to work (depending on the method used).The expected constant time property of a hash table assumes that theload factor is kept below some bound. For a fixed number of buckets,the time for a lookup grows with the number of entries and thereforethe desired constant time is not achieved.

关于java - 为什么 Hashtable 中有这么多空引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49106521/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com