Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map with fast and constant get() for Java 7 [closed]

While using the HashMap that java 7 provides, i ran into the problem that get() evolves from O(1) to O(n) as described here and solved in java 8.

But because i have to stick to java 7 and can't upgrade the project, i am looking for a library or any way to have a Map with a fast and constant get().

like image 244
Alexton Avatar asked Sep 18 '15 10:09

Alexton


1 Answers

The essence of the change in Java 8:

From your link Performance Improvement for HashMap in Java 8

Buckets containing a large number of colliding keys will store their entries in a balanced tree instead of a linked list after certain threshold is reached.

You could achieve the equivalent by reducing the number of colliding keys by improving your hashCode implementation.

Without details of your hashCode calculation or the pattern of the values it is difficult to advise further.

like image 158
OldCurmudgeon Avatar answered Nov 12 '22 15:11

OldCurmudgeon