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. Linear probing continues to work even when all hashCodes collide, just more slowly.
| Access | Constructor and Description |
|---|---|
| public | |
| public | IdentityMap(int
The backing array size is initialCapacity / loadFactor, increased to the next power of two. initialCapacity)Creates a new map with a load factor of 0.8. |
| public | IdentityMap(int
The backing array size is initialCapacity / loadFactor, increased to the next power of two. initialCapacity, float loadFactor)Creates a new map with the specified initial capacity and load factor. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | hashCode()
Overrides com. Returns a hash code value for this object. |
| pack-priv int | locateKey(K key)
Overrides com. Returns the index of the key if already present, else -(index + 1) for the next empty index. |
| protected int | place(K item)
Overrides com. Returns an index >= 0 and <= |
| IdentityMap | back to summary |
|---|---|
| public IdentityMap() Creates a new map with an initial capacity of 51 and a load factor of 0.8. | |
| IdentityMap | back to summary |
|---|---|
| public IdentityMap(int initialCapacity) Creates a new map with a load factor of 0.8.
| |
| IdentityMap | back to summary |
|---|---|
| public IdentityMap(int initialCapacity, float loadFactor) Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before growing the backing table.
| |
| IdentityMap | back to summary |
|---|---|
| public IdentityMap(IdentityMap<K, V> map) Creates a new map identical to the specified map. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides com. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| locateKey | back to summary |
|---|---|
| pack-priv int locateKey(K key) Overrides com. Doc from com. Returns the index of the key if already present, else -(index + 1) for the next empty index. This can be overridden in this
pacakge to compare for equality differently than | |
| place | back to summary |
|---|---|
| protected int place(K item) Overrides com. Doc from com. Returns an index >= 0 and <=
The default implementation uses Fibonacci hashing on the item's
This method can be overridden to customizing hashing. This may be useful eg in the unlikely event that most hashcodes are
Fibonacci numbers, if keys provide poor or incorrect hashcodes, or to simplify hashing if keys provide high quality
hashcodes and don't need Fibonacci hashing: | |