Java code that uses only arrays to implement hash tables

I'll start this review by saying that I understand how hash tables work, but I'm not sure how to implement a hash table from scratch using only primitives

Can anyone use only the Java code implementation of array provided hash table?

How did I start writing hash tables in Java?

How to encode a linked list again using only primitives?

Cheers!

Solution

The code given by openjdk is difficult to understand, so I will write a short idea on how to do it

One of my recent methods is to use the array itself as a symbol table The index of the array will then be the key (hash key) and the element value (whatever you want to store) Because the array has a fixed size and the hash key can be any integer, we face the challenge of tailoring the hash values so that they are within the same range as the size of the array If the length of the array is 5, the key needs to be between 0 and 4 Otherwise, we will put the value in the slot outside the array = > many exceptions

This challenge becomes particularly interesting when you want to avoid collisions

You can find a lot of help on this page on Princeton

Good luck!

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
分享
二维码
< <上一篇
下一篇>>