How to create your own HashMap in Java?

I know about the hashing algorithm and hashCode()for converting the "key" to an equivalent integer (using some mathematically random expression), which is then compressed and stored in the codes.

But can someone point me to an implementation, or at least a data structure to be used as a baseline?

I did not find it anywhere on the Internet.

+3
source share
4 answers

Just use eclipse and use the latest version of the JDK. The source code for the Java base packages connects to the JDK. Open the HashMap class and you're good to go. Some of the method implementations may come from AbstractMap, AbstractCollection, etc. This is due to the proper OO design. You can navigate all JDK classes in your eclipse.

UPDATE: Why Eclipe (or IDE) instead of opening a zip file? The IDE can be used to move between classes and is generally useful for reading code. Note that not all method implementations are in the same file, such as HashMap.java, and therefore simple text editors such as Notepad ++ or the text panel may not be enough. A full-fledged IDE, such as eclipse / IDEA, can make it a lot easier. At least it worked for me :)

+3

, java.util.Map

+2

, . , , .

, . , - ..

java.util.Map, , .

+1

HashMap

http://javaexplorer03.blogspot.com/2015/10/create-own-hashmap.html

1. -. Entry HashMap. : , - ( ).

2. put(), hashmap. (hashcode% SIZE)

. :, new Entry.

. : , , .

3. The get () method: returns an element in hashmap a. Define the bucket of the element by computing the hashcode (hashcode% SIZE) of the key and return the element using the equals method.

+1
source

Source: https://habr.com/ru/post/1735806/


All Articles