INITIAL_CAPACITY or smaller 256.
The key/value pairs are kept in an expanding flat object array with keys at even indices and
values at odd indices. If the map has smaller or equal to HASH_THRESHOLD entries, there
is no additional hash data structure and comparisons are done via linear checking of the
key/value pairs. For the case where the equality check is particularly cheap (e.g., just an
object identity comparison), this limit below which the map is without an actual hash table is
higher and configured at HASH_THRESHOLD_IDENTITY_COMPARE.
When the hash table needs to be constructed, the field hashArray becomes a new hash
array where an entry of 0 means no hit and otherwise denotes the entry number in the
entries array. The hash array is interpreted as an actual byte array if the indices fit
within 8 bit, or as an array of short values if the indices fit within 16 bit, or as an array of
integer values in other cases.
Hash collisions are handled by chaining a linked list of CollisionLink objects that take
the place of the values in the entries array.
Removing entries will put null into the entries array. If the occupation of the
map falls below a specific threshold, the map will be compressed via the
maybeCompress(int) method.
| Modifier and Type | Class and Description |
|---|---|
| private static class | EconomicMapImpl.
Links the collisions. |
| private abstract class |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | COMPRESS_IMMEDIATE_CAPACITY
Maximum number of entries that are moved linearly forward if a key is removed. |
| private int | deletedEntries
Number of deleted entries. |
| private Object[] | entries
Entries array with even indices storing keys and odd indices storing values. |
| private static final int | HASH_THRESHOLD
Number of entries above which a hash table is created. |
| private static final int | HASH_THRESHOLD_IDENTITY_COMPARE
Number of entries above which a hash table is created when equality can be checked with object identity. |
| private byte[] | hashArray
Hash array that is interpreted either as byte or short or int array depending on number of map entries. |
| private static final int | INITIAL_CAPACITY
Initial number of key/value pair entries that is allocated in the first entries array. |
| private final boolean | |
| private static final int | LARGE_HASH_THRESHOLD
Number of entries above which more than 1 byte is necessary for the hash index. |
| private static final int | MAX_ELEMENT_COUNT
Maximum number of entries allowed in the map. |
| private static final int | MIN_CAPACITY_INCREASE
Minimum number of key/value pair entries added when the entries array is increased in size. |
| private final Equivalence | strategy
The strategy used for comparing keys or |
| private int | totalEntries
Total number of entries (actual entries plus deleted entries). |
| private static final int | VERY_LARGE_HASH_THRESHOLD
Number of entries above which more than 2 bytes are are necessary for the hash index. |
| Access | Constructor and Description |
|---|---|
| private | |
| private | |
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(K element)
Implements org. Adds |
| private void | |
| public void | clear()
Implements org. Removes all of the mappings from this map. |
| private boolean | |
| private int | |
| public boolean | contains(K element)
Implements org. Returns |
| public boolean | containsKey(K key)
Implements org. Returns |
| public static <K, V> EconomicMapImpl | |
| public static <K, V> EconomicMapImpl | |
| public static <K, V> EconomicMapImpl | |
| public static <K, V> EconomicMapImpl | |
| private void | |
| private int | |
| private int | |
| private int | findAndRemoveWithCollision(Object key, EconomicMapImpl.
|
| private int | |
| private int | |
| private int | |
| public V | get(K key)
Implements org. Returns the value to which |
| public MapCursor | getEntries()
Implements org. Returns a |
| public Equivalence | getEquivalenceStrategy()
Overrides default org. Returns the strategy used to compare keys. |
| private int | |
| private int | |
| private int | |
| private int | |
| private Object | |
| public Iterable | getKeys()
Implements org. Returns a |
| private Object | |
| private Object | |
| public Iterable | getValues()
Implements org. Returns a |
| private void | |
| private boolean | |
| private void | |
| private boolean | |
| private static <K, V> EconomicMapImpl | |
| public boolean | isEmpty()
Implements org. Returns |
| public Iterator | |
| private int | maybeCompress(int nextIndex)
Compresses the graph if there is a large number of deleted entries and returns the translated new next index. |
| public V | put(K key, V value)
Implements org. Associates |
| private void | |
| private int | remove(int indexToRemove)
Implements org. Removes the element at the specific index and returns the index of the next element. |
| public void | remove(K element)
Implements org. Removes |
| public V | removeKey(K key)
Implements org. Removes the mapping for |
| public void | replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
Implements org. Replaces each entry's value with the result of invoking |
| private void | |
| private void | |
| private void | |
| private void | |
| public int | size()
Implements org. Returns the number of key-value mappings in this map. |
| public String | |
| pack-priv static <K, V> String |
| COMPRESS_IMMEDIATE_CAPACITY | back to summary |
|---|---|
| private static final int COMPRESS_IMMEDIATE_CAPACITY Maximum number of entries that are moved linearly forward if a key is removed. | |
| deletedEntries | back to summary |
|---|---|
| private int deletedEntries Number of deleted entries. | |
| entries | back to summary |
|---|---|
| private Object[] entries Entries array with even indices storing keys and odd indices storing values. | |
| HASH_THRESHOLD | back to summary |
|---|---|
| private static final int HASH_THRESHOLD Number of entries above which a hash table is created. | |
| HASH_THRESHOLD_IDENTITY_COMPARE | back to summary |
|---|---|
| private static final int HASH_THRESHOLD_IDENTITY_COMPARE Number of entries above which a hash table is created when equality can be checked with object identity. | |
| hashArray | back to summary |
|---|---|
| private byte[] hashArray Hash array that is interpreted either as byte or short or int array depending on number of map entries. | |
| INITIAL_CAPACITY | back to summary |
|---|---|
| private static final int INITIAL_CAPACITY Initial number of key/value pair entries that is allocated in the first entries array. | |
| isSet | back to summary |
|---|---|
| private final boolean isSet | |
| LARGE_HASH_THRESHOLD | back to summary |
|---|---|
| private static final int LARGE_HASH_THRESHOLD Number of entries above which more than 1 byte is necessary for the hash index. | |
| MAX_ELEMENT_COUNT | back to summary |
|---|---|
| private static final int MAX_ELEMENT_COUNT Maximum number of entries allowed in the map. | |
| MIN_CAPACITY_INCREASE | back to summary |
|---|---|
| private static final int MIN_CAPACITY_INCREASE Minimum number of key/value pair entries added when the entries array is increased in size. | |
| strategy | back to summary |
|---|---|
| private final Equivalence strategy The strategy used for comparing keys or | |
| totalEntries | back to summary |
|---|---|
| private int totalEntries Total number of entries (actual entries plus deleted entries). | |
| VERY_LARGE_HASH_THRESHOLD | back to summary |
|---|---|
| private static final int VERY_LARGE_HASH_THRESHOLD Number of entries above which more than 2 bytes are are necessary for the hash index. | |
| EconomicMapImpl | back to summary |
|---|---|
| private EconomicMapImpl(Equivalence strategy, boolean isSet) | |
| EconomicMapImpl | back to summary |
|---|---|
| private EconomicMapImpl(Equivalence strategy, int initialCapacity, boolean isSet) | |
| EconomicMapImpl | back to summary |
|---|---|
| private EconomicMapImpl(Equivalence strategy, UnmodifiableEconomicMap<K, V> other, boolean isSet) | |
| EconomicMapImpl | back to summary |
|---|---|
| private EconomicMapImpl(Equivalence strategy, UnmodifiableEconomicSet<K> other, boolean isSet) | |
| add | back to summary |
|---|---|
| public boolean add(K element) Implements org. Doc from org. Adds
| |
| checkKeyNonNull | back to summary |
|---|---|
| private void checkKeyNonNull(K key) | |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Doc from org. Removes all of the mappings from this map. The map will be empty after this call returns.
| |
| compareKeys | back to summary |
|---|---|
| private boolean compareKeys(Object key, Object entryKey) | |
| compressLarge | back to summary |
|---|---|
| private int compressLarge(int nextIndex) Compresses the graph and returns the translated new next index. | |
| contains | back to summary |
|---|---|
| public boolean contains(K element) Implements org. Doc from org. Returns
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(K key) Implements org. Doc from org. Returns
| |
| create | back to summary |
|---|---|
| public static <K, V> EconomicMapImpl | |
| create | back to summary |
|---|---|
| public static <K, V> EconomicMapImpl | |
| create | back to summary |
|---|---|
| public static <K, V> EconomicMapImpl | |
| create | back to summary |
|---|---|
| public static <K, V> EconomicMapImpl | |
| createHash | back to summary |
|---|---|
| private void createHash() | |
| find | back to summary |
|---|---|
| private int find(K key) | |
| findAndRemoveHash | back to summary |
|---|---|
| private int findAndRemoveHash(Object key) | |
| findAndRemoveWithCollision | back to summary |
|---|---|
| private int findAndRemoveWithCollision(Object key, EconomicMapImpl. | |
| findHash | back to summary |
|---|---|
| private int findHash(K key) | |
| findLinear | back to summary |
|---|---|
| private int findLinear(K key) | |
| findWithCollision | back to summary |
|---|---|
| private int findWithCollision(K key, EconomicMapImpl. | |
| get | back to summary |
|---|---|
| public V get(K key) Implements org. Doc from org. Returns the value to which
| |
| getEntries | back to summary |
|---|---|
| public MapCursor Implements org. Doc from org. Returns a
| |
| getEquivalenceStrategy | back to summary |
|---|---|
| public Equivalence getEquivalenceStrategy() Overrides default org. Doc from org. Returns the strategy used to compare keys.
| |
| getHashArray | back to summary |
|---|---|
| private int getHashArray(int index) | |
| getHashIndex | back to summary |
|---|---|
| private int getHashIndex(Object key) | |
| getHashTableSize | back to summary |
|---|---|
| private int getHashTableSize() | |
| getHashThreshold | back to summary |
|---|---|
| private int getHashThreshold() Number of entries above which a hash table should be constructed. | |
| getKey | back to summary |
|---|---|
| private Object getKey(int index) | |
| getKeys | back to summary |
|---|---|
| public Iterable Implements org. Doc from org. Returns a
| |
| getRawValue | back to summary |
|---|---|
| private Object getRawValue(int index) | |
| getValue | back to summary |
|---|---|
| private Object getValue(int index) | |
| getValues | back to summary |
|---|---|
| public Iterable Implements org. Doc from org. Returns a
| |
| grow | back to summary |
|---|---|
| private void grow() | |
| hasHashArray | back to summary |
|---|---|
| private boolean hasHashArray() | |
| init | back to summary |
|---|---|
| private void init(int size) | |
| initFrom | back to summary |
|---|---|
private boolean initFrom(Object o)
| |
| intercept | back to summary |
|---|---|
| private static <K, V> EconomicMapImpl Intercept method for debugging purposes. | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements org. Doc from org. Returns
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements java. Doc from java. Returns an iterator over elements of type | |
| maybeCompress | back to summary |
|---|---|
| private int maybeCompress(int nextIndex) Compresses the graph if there is a large number of deleted entries and returns the translated new next index. | |
| put | back to summary |
|---|---|
| public V put(K key, V value) Implements org. Doc from org. Associates
| |
| putHashEntry | back to summary |
|---|---|
| private void putHashEntry(Object key, int entryIndex, boolean rehashOnCollision) | |
| remove | back to summary |
|---|---|
| private int remove(int indexToRemove) Implements org. Removes the element at the specific index and returns the index of the next element. This can be a different value if graph compression was triggered. | |
| remove | back to summary |
|---|---|
| public void remove(K element) Implements org. Doc from org. Removes
| |
| removeKey | back to summary |
|---|---|
| public V removeKey(K key) Implements org. Doc from org. Removes the mapping for
| |
| replaceAll | back to summary |
|---|---|
| public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) Implements org. Doc from org. Replaces each entry's value with the result of invoking
| |
| setHashArray | back to summary |
|---|---|
| private void setHashArray(int index, int value) | |
| setKey | back to summary |
|---|---|
| private void setKey(int index, Object newValue) | |
| setRawValue | back to summary |
|---|---|
| private void setRawValue(int index, Object newValue) | |
| setValue | back to summary |
|---|---|
| private void setValue(int index, Object newValue) | |
| size | back to summary |
|---|---|
| public int size() Implements org. Doc from org. Returns the number of key-value mappings in this map.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| toString | back to summary |
|---|---|
| pack-priv static <K, V> String toString(boolean isSet, int size, MapCursor<K, V> cursor) | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final int | next
Index plus one of the next entry in the collision link chain. |
| pack-priv final Object |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| next | back to summary |
|---|---|
| pack-priv final int next Index plus one of the next entry in the collision link chain. | |
| value | back to summary |
|---|---|
| pack-priv final Object value | |
| CollisionLink | back to summary |
|---|---|
| pack-priv CollisionLink(Object value, int next) | |
| Modifier and Type | Field and Description |
|---|---|
| protected int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public void | remove()
Overrides default java. Removes from the underlying collection the last element returned by this iterator (optional operation). |
| current | back to summary |
|---|---|
| protected int current | |
| SparseMapIterator | back to summary |
|---|---|
| private SparseMapIterator() | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |