MutableObjectIntMap
public final class MutableObjectIntMap<K extends Object> extends ObjectIntMap
MutableObjectIntMap is a container with a MutableMap-like interface for keys with reference types and Int primitives for 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 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 |
|---|
<K extends Object> MutableObjectIntMap(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(@NonNull K key)Removes the specified |
final void |
minusAssign(@NonNull K[] keys)Removes the specified |
final void |
minusAssign(@NonNull Iterable<@NonNull K> keys)Removes the specified |
final void |
minusAssign(@NonNull ScatterSet<@NonNull K> keys)Removes the specified |
final void |
minusAssign(@NonNull Sequence<@NonNull K> keys)Removes the specified |
final void |
plusAssign(@NonNull ObjectIntMap<@NonNull K> from)Puts all the key/value mappings in the |
final void |
|
final int |
|
final void |
putAll(@NonNull ObjectIntMap<@NonNull K> from)Puts all the key/value mappings in the |
final void |
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
MutableObjectIntMap
public <K extends Object> MutableObjectIntMap(int initialCapacity)
Creates a new MutableObjectIntMap
| 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(@NonNull K key, @NonNull Function0<@NonNull Integer> defaultValue)
Returns the value to which the specified key is mapped, if the value is present in the map. Otherwise, calls defaultValue() and puts the result in the map associated with key.
minusAssign
public final void minusAssign(@NonNull K key)
Removes the specified key and its associated value from the map.
minusAssign
public final void minusAssign(@NonNull K[] keys)
Removes the specified keys and their associated value from the map.
minusAssign
public final void minusAssign(@NonNull Iterable<@NonNull K> keys)
Removes the specified keys and their associated value from the map.
minusAssign
public final void minusAssign(@NonNull ScatterSet<@NonNull K> keys)
Removes the specified keys and their associated value from the map.
minusAssign
public final void minusAssign(@NonNull Sequence<@NonNull K> keys)
Removes the specified keys and their associated value from the map.
plusAssign
public final void plusAssign(@NonNull ObjectIntMap<@NonNull K> from)
Puts all the key/value mappings in the from map into this map.
put
public final void put(@NonNull K 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.
put
public final int put(@NonNull K 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 ObjectIntMap<@NonNull K> from)
Puts all the key/value mappings in the from map into this map.
remove
public final void remove(@NonNull K key)
Removes the specified key and its associated value from the map.
remove
public final boolean remove(@NonNull K 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 K, @NonNull Integer, @NonNull Boolean> predicate
)
Removes any mapping for which the specified predicate returns true.
set
public final void set(@NonNull K 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 MutableObjectIntMap'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.