public class IdentityMap<K,V> extends ObjectMap<K,V>
This class performs fast contains and remove (typically O(1), worst case O(n) but that is rare in practice). Add may be slightly slower, depending on hash collisions. Hashcodes are rehashed to reduce collisions and the need to resize. Load factors greater than 0.91 greatly increase the chances to resize to the next higher POT size.
Unordered sets and maps are not designed to provide especially fast iteration. Iteration is faster with OrderedSet and OrderedMap.
This implementation uses linear probing with the backward shift algorithm for removal. Hashcodes are rehashed using Fibonacci hashing, instead of the more common power-of-two mask, to better distribute poor hashCodes (see Malte Skarupke's blog post). Linear probing continues to work even when all hashCodes collide, just more slowly.
ObjectMap.Entries<K,V>, ObjectMap.Entry<K,V>, ObjectMap.Keys<K>, ObjectMap.Values<V>
Constructor and Description |
---|
IdentityMap()
Creates a new map with an initial capacity of 51 and a load factor of 0.8.
|
IdentityMap(IdentityMap<K,V> map)
Creates a new map identical to the specified map.
|
IdentityMap(int initialCapacity)
Creates a new map with a load factor of 0.8.
|
IdentityMap(int initialCapacity,
float loadFactor)
Creates a new map with the specified initial capacity and load factor.
|
Modifier and Type | Method and Description |
---|---|
int |
hashCode() |
clear, clear, containsKey, containsValue, ensureCapacity, entries, equals, equalsIdentity, findKey, get, get, isEmpty, iterator, keys, notEmpty, put, putAll, remove, shrink, toString, toString, values
forEach, spliterator
public IdentityMap()
public IdentityMap(int initialCapacity)
initialCapacity
- If not a power of two, it is increased to the next nearest power of two.public IdentityMap(int initialCapacity, float loadFactor)
initialCapacity
- If not a power of two, it is increased to the next nearest power of two.public IdentityMap(IdentityMap<K,V> map)
Copyright © 2021. All rights reserved.