MutableIntObjectMap
public final class MutableIntObjectMap<V extends Object> extends IntObjectMap
MutableIntObjectMap is a container with a MutableMap-like interface for keys with Int primitives and reference type values.
The underlying implementation is designed to avoid allocations from boxing, and insertion, removal, retrieval, and iteration operations. 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.
| See also | |
|---|---|
ScatterMap |
Summary
Public constructors |
|---|
<V extends Object> MutableIntObjectMap(int initialCapacity)Creates a new |
Public methods |
|
|---|---|
final void |
clear()Removes all mappings from this map. |
final @NonNull V |
Returns the value to which the specified |
final void |
minusAssign(int key)Removes the specified |
final void |
minusAssign(@NonNull int[] keys)Removes the specified |
final void |
minusAssign(@NonNull IntList keys)Removes the specified |
final void |
minusAssign(@NonNull IntSet keys)Removes the specified |
final void |
plusAssign(@NonNull IntObjectMap<@NonNull V> from)Puts all the key/value mappings in the |
final V |
|
final void |
putAll(@NonNull IntObjectMap<@NonNull V> from)Puts all the key/value mappings in the |
final V |
remove(int key)Removes the specified |
final boolean |
Removes the specified |
final void |
Removes any mapping for which the specified |
final void |
|
final int |
trim()Trims this |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
MutableIntObjectMap
public <V extends Object> MutableIntObjectMap(int initialCapacity)
Creates a new MutableIntObjectMap
| Parameters | |
|---|---|
int initialCapacity |
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. |
Public methods
getOrPut
public final @NonNull V getOrPut(int key, @NonNull Function0<@NonNull V> defaultValue)
Returns the value to which the specified key is mapped, if the value is present in the map and not null. Otherwise, calls defaultValue() and puts the result in the map associated with key.
minusAssign
public final void minusAssign(int key)
Removes the specified key and its associated value from the map.
minusAssign
public final void minusAssign(@NonNull int[] keys)
Removes the specified keys and their associated value from the map.
minusAssign
public final void minusAssign(@NonNull IntList keys)
Removes the specified keys and their associated value from the map.
minusAssign
public final void minusAssign(@NonNull IntSet keys)
Removes the specified keys and their associated value from the map.
plusAssign
public final void plusAssign(@NonNull IntObjectMap<@NonNull V> from)
Puts all the key/value mappings in the from map into this map.
put
public final V put(int key, @NonNull V 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.
putAll
public final void putAll(@NonNull IntObjectMap<@NonNull V> from)
Puts all the key/value mappings in the from map into this map.
remove
public final V remove(int key)
Removes the specified key and its associated value from the map. If the key was present in the map, this function returns the value that was present before removal.
remove
public final boolean remove(int key, @NonNull V value)
Removes the specified key and its associated value from the map if the associated value equals value. Returns whether the removal happened.
removeIf
public final void removeIf(
@NonNull Function2<@NonNull Integer, @NonNull V, @NonNull Boolean> predicate
)
Removes any mapping for which the specified predicate returns true.
set
public final void set(int key, @NonNull V 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.
trim
public final int trim()
Trims this MutableIntObjectMap's storage so it is sized appropriately to hold the current mappings.
Returns the number of empty entries removed from this map's storage. Returns be 0 if no trimming is necessary or possible.