简体   繁体   中英

Why so many null references in Hashtable

在此处输入图片说明

I was trying to debug the Hashtable contents and got curious why there are so many Null references init.

This is just how Hash tables work. For reference

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

There are normally more buckets than values, that's why some buckets are empty.

This is important for performance of the hash table.

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 number of buckets. As the load factor grows larger, the hash table becomes slower, and it may even fail to work (depending on the method used). The expected constant time property of a hash table assumes that the load factor is kept below some bound. For a fixed number of buckets, the time for a lookup grows with the number of entries and therefore the desired constant time is not achieved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM