MutableIntIntMap
public final class MutableIntIntMap extends IntIntMap
MutableIntIntMap is a container with a MutableMap-like interface for Int primitive keys and Int primitive 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 | |
|---|---|
MutableScatterMap |
Summary
Public constructors |
|---|
MutableIntIntMap(int initialCapacity)Creates a new |
Public methods |
|
|---|---|
final void |
clear()Removes all mappings from this map. |
final int |
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 IntIntMap from)Puts all the key/value mappings in the |
final void |
put(int key, int value) |
final int |
put(int key, int value, int default) |
final void |
Puts all the key/value mappings in the |
final void |
remove(int key)Removes the specified |
final boolean |
remove(int key, int value)Removes the specified |
final void |
Removes any mapping for which the specified |
final void |
set(int key, int value) |
final int |
trim()Trims this |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
MutableIntIntMap
public MutableIntIntMap(int initialCapacity)
Creates a new MutableIntIntMap
| 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 int getOrPut(int key, @NonNull Function0<@NonNull Integer> 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 IntIntMap from)
Puts all the key/value mappings in the from map into this map.
put
public final void put(int key, int 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.
put
public final int put(int key, int value, int default)
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.
putAll
public final void putAll(@NonNull IntIntMap from)
Puts all the key/value mappings in the from map into this map.
remove
public final void remove(int key)
Removes the specified key and its associated value from the map.
remove
public final boolean remove(int key, int 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 Integer, @NonNull Boolean> predicate
)
Removes any mapping for which the specified predicate returns true.
set
public final void set(int key, int 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 MutableIntIntMap'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.