Mutable Scatter Map
MutableScatterMap is a container with a Map-like interface based on a flat hash table implementation (the key/value mappings are not stored by nodes but directly into arrays). The underlying implementation is designed to avoid all allocations on insertion, removal, retrieval, and iteration. Allocations may still happen on insertion when the underlying storage needs to grow to accommodate newly added entries to the table. In addition, this implementation minimizes memory usage by avoiding the use of separate objects to hold key/value pairs.
This implementation makes no guarantee as to the order of the keys and values stored, nor does it make guarantees that the order remains constant over time.
This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the map (insertion or removal for instance), the calling code must provide the appropriate synchronization. Multiple threads are safe to read from this map concurrently if no write is happening.
Note: when a Map is absolutely necessary, you can use the method asMap to create a thin wrapper around a MutableScatterMap. Please refer to asMap for more details and caveats.
Note: when a MutableMap is absolutely necessary, you can use the method asMutableMap to create a thin wrapper around a MutableScatterMap. Please refer to asMutableMap for more details and caveats.
MutableScatterMap and SimpleArrayMap: like SimpleArrayMap, MutableScatterMap is designed to avoid the allocation of extra objects when inserting new entries in the map. However, the implementation of MutableScatterMap offers better performance characteristics compared to SimpleArrayMap and is thus generally preferable. If memory usage is a concern, SimpleArrayMap automatically shrinks its storage to avoid using more memory than necessary. You can also control memory usage with MutableScatterMap by manually calling MutableScatterMap.trim.
Parameters
The initial desired capacity for this container. the container will honor this value by guaranteeing its internal structures can hold that many entries without requiring any allocations. The initial capacity can be set to 0.
See also
Constructors
Creates a new MutableScatterMap
Properties
Functions
Wraps this ScatterMap with a Map interface. The Map is backed by the ScatterMap, so changes to the ScatterMap are reflected in the Map. If the ScatterMap is modified while an iteration over the Map is in progress, the results of the iteration are undefined.
Wraps this ScatterMap with a MutableMap interface. The MutableMap is backed by the ScatterMap, so changes to the ScatterMap are reflected in the MutableMap and vice-versa. If the ScatterMap is modified while an iteration over the MutableMap is in progress (and vice- versa), the results of the iteration are undefined.
Returns true if the specified key is present in this hash map, false otherwise.
Returns true if the specified value is present in this hash map, false otherwise.
Iterates over every key stored in this map by invoking the specified block lambda.
Iterates over every value stored in this map by invoking the specified block lambda.
Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
Returns true if this map is not empty.
Puts all the key/value mappings in the from map into this map.
Puts all the pairs into this map, using the first component of the pair as the key, and the second component as the value.
Puts the key/value mapping from the pair in this map, using the first element as the key, and the second element as the value.
Creates a new mapping from key to value in this map. If key is already present in the map, the association is modified and the previously associated value is replaced with value. If key is not present, a new entry is added to the map, which may require to grow the underlying storage and cause allocations. Return the previous value associated with the key, or null if the key was not present in the map.
Creates a new mapping from key to value in this map. If key is already present in the map, the association is modified and the previously associated value is replaced with value. If key is not present, a new entry is added to the map, which may require to grow the underlying storage and cause allocations.
Trims this MutableScatterMap's storage so it is sized appropriately to hold the current mappings.