From java 8 onwords, there has been a performance improvement for HashMap objects, where there are many conflicts in the keys, using balanced trees rather than linked lists to store records in the map. The main idea is that after the number of elements in the hash bucket exceeds a certain threshold, this bucket will switch from using a linked list of records to a balanced tree. In the case of high hash collisions, this will improve worst case performance from O(n) to O(log n).
Basically, when the bucket gets too large (currently: TREEIFY_THRESHOLD = 8 ), the HashMap dynamically replaces it with a special implementation of the tree map. This method, and not the pessimistic O(n) , is much better than O(log n) .
The bunkers (elements or nodes) of TreeNodes can pass and be used like any other, but additionally support quick search during overpopulation. However, since the vast majority of boxes are not overpopulated during normal use, checking for tree boxes may be delayed by tabular methods.
Letters
Tree (that is, bins whose elements are all TreeNodes ) are ordered mainly with hashCode, but in the case of links, if two elements have the same " class C implements Comparable<C> ", enter them compareTo() > used to streamline.
Because TreeNodes approximately two times larger than regular nodes, we only use them when there are enough nodes in the boxes. And when they get too small (due to deletion or resizing), they are converted back to regular mailboxes (currently: UNTREEIFY_THRESHOLD = 6 ). When used with a well-distributed user hashCodes tree baskets are rarely used.
Link to java doc
Collection Improvements
source share