MutableObjectIntMap
-
Cmn
class MutableObjectIntMap<K : Any?> : 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 : Any?> MutableObjectIntMap(initialCapacity: Int) Creates a new |
Cmn
|
Public functions |
||
---|---|---|
Unit |
clear() Removes all mappings from this map. |
Cmn
|
inline Int |
Returns the value to which the specified |
Cmn
|
inline operator Unit |
minusAssign(key: K) Removes the specified |
Cmn
|
inline operator Unit |
minusAssign(keys: Array<K>) Removes the specified |
Cmn
|
inline operator Unit |
minusAssign(keys: Iterable<K>) Removes the specified |
Cmn
|
inline operator Unit |
minusAssign(keys: ScatterSet<K>) Removes the specified |
Cmn
|
inline operator Unit |
minusAssign(keys: Sequence<K>) Removes the specified |
Cmn
|
inline operator Unit |
plusAssign(from: ObjectIntMap<K>) Puts all the key/value mappings in the |
Cmn
|
Unit |
Cmn
|
|
Int |
Cmn
|
|
Unit |
putAll(from: ObjectIntMap<K>) Puts all the key/value mappings in the |
Cmn
|
Unit |
remove(key: K) Removes the specified |
Cmn
|
Boolean |
Removes the specified |
Cmn
|
inline Unit |
Removes any mapping for which the specified |
Cmn
|
operator Unit |
Cmn
|
|
Int |
trim() Trims this |
Cmn
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited properties |
---|
Public constructors
MutableObjectIntMap
<K : Any?> MutableObjectIntMap(initialCapacity: Int = DefaultScatterCapacity)
Creates a new MutableObjectIntMap
Parameters | |
---|---|
initialCapacity: Int = DefaultScatterCapacity |
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 functions
getOrPut
inline fun getOrPut(key: K, defaultValue: () -> Int): Int
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
inline operator fun minusAssign(key: K): Unit
Removes the specified key
and its associated value from the map.
minusAssign
inline operator fun minusAssign(keys: Array<K>): Unit
Removes the specified keys
and their associated value from the map.
minusAssign
inline operator fun minusAssign(keys: Iterable<K>): Unit
Removes the specified keys
and their associated value from the map.
minusAssign
inline operator fun minusAssign(keys: ScatterSet<K>): Unit
Removes the specified keys
and their associated value from the map.
minusAssign
inline operator fun minusAssign(keys: Sequence<K>): Unit
Removes the specified keys
and their associated value from the map.
plusAssign
inline operator fun plusAssign(from: ObjectIntMap<K>): Unit
Puts all the key/value mappings in the from
map into this map.
put
fun put(key: K, value: Int): Unit
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
fun put(key: K, value: Int, default: Int): Int
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
fun putAll(from: ObjectIntMap<K>): Unit
Puts all the key/value mappings in the from
map into this map.
remove
fun remove(key: K, value: Int): Boolean
Removes the specified key
and its associated value from the map if the associated value equals value
. Returns whether the removal happened.
removeIf
inline fun removeIf(predicate: (K, Int) -> Boolean): Unit
Removes any mapping for which the specified predicate
returns true.
set
operator fun set(key: K, value: Int): Unit
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
fun trim(): Int
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.