Java – specify the appropriate table size for hash

If I have a 1000 key, what is the appropriate size of my hash table?

Solution

This depends on the load factor ("percentage full" point, the table will increase its size and redistribute its elements) If you know you have 1000 entries and the number will never change, you can set the load factor to 1.0 and the initial size to 1000 for maximum efficiency If you are not sure about the specific size, you can set the load factor to 0.75 and the initial size to 1334 (expected size / LF) to achieve very good performance and require additional memory

You can set the load factor using the following constructor:

Hashtable(int initialCapacity,float loadFactor)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>