Which Java hash structure supports linear chaining?

For homework, I have to implement many hash functions in C ++ or Java. I am comfortable working with Java, but I have not used its hash functions.

I want a hash structure to bind colliding keys. Like this:

enter image description here

Is LinkedHashMap the right choice here? Is this a hashmap ? Or? Why?

+4
source share
5 answers

Well, just regular HashMap links that fall into the same bucket (each bucket is really an element in an array of linked lists). A LinkedHashMap also maintains links between posts to maintain the insertion order, but this is not what happens on your chart.

+2
source

HashMap does this. What LinkedHashMap does is placeholder key binding.

+1
source

I think that the standard HashMap already works like this: it has several bunkers, and elements with counter hash codes fall into the same tray. You can find the source code for HashMap yourself: in your JDK installation directory there is a src.zip file that contains the source code.

LinkedHashMap is just a HashMap combined with List to track the insertion order of elements on a map. The word β€œlinked” in his name has nothing to do with how items are stored in one box.

+1
source

You can use hashmap

 Map<String,ArrayList<Object>> map = new HashMap<String,ArrayList<Object>>(); 

Instead of the object, specify the type that you need.

HashMap provides fast random access. Also have:

TreeMap - data sorted by key. LinkedHashMap - data stored in the order they are entered into the container.

0
source

LinkedHashMap is designed to create an iterative map with a predictable key order. Inside, HashHap is free to use any means that, in its opinion, are suitable for handling key collisions, which may or may not be a linked list. I do not think that there is any standard guarantee that the mechanism for reinforcing collision buckets for using a linked list in Java, but in practice they can.

0
source

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


All Articles