MutableObjectIntMap



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.

Summary

Public constructors

<K : Any?> MutableObjectIntMap(initialCapacity: Int)

Creates a new MutableObjectIntMap

Cmn

Public functions

Unit

Removes all mappings from this map.

Cmn
inline Int
getOrPut(key: K, defaultValue: () -> Int)

Returns the value to which the specified key is mapped, if the value is present in the map.

Cmn
inline operator Unit
minusAssign(key: K)

Removes the specified key and its associated value from the map.

Cmn
inline operator Unit
minusAssign(keys: Array<K>)

Removes the specified keys and their associated value from the map.

Cmn
inline operator Unit

Removes the specified keys and their associated value from the map.

Cmn
inline operator Unit

Removes the specified keys and their associated value from the map.

Cmn
inline operator Unit

Removes the specified keys and their associated value from the map.

Cmn
inline operator Unit

Puts all the key/value mappings in the from map into this map.

Cmn
Unit
put(key: K, value: Int)

Creates a new mapping from key to value in this map.

Cmn
Int
put(key: K, value: Int, default: Int)

Creates a new mapping from key to value in this map.

Cmn
Unit
putAll(from: ObjectIntMap<K>)

Puts all the key/value mappings in the from map into this map.

Cmn
Unit
remove(key: K)

Removes the specified key and its associated value from the map.

Cmn
Boolean
remove(key: K, value: Int)

Removes the specified key and its associated value from the map if the associated value equals value.

Cmn
inline Unit
removeIf(predicate: (K, Int) -> Boolean)

Removes any mapping for which the specified predicate returns true.

Cmn
operator Unit
set(key: K, value: Int)

Creates a new mapping from key to value in this map.

Cmn
Int

Trims this MutableObjectIntMap's storage so it is sized appropriately to hold the current mappings.

Cmn

Inherited functions

From androidx.collection.ObjectIntMap
inline Boolean
all(predicate: (K, Int) -> Boolean)

Returns true if all entries match the given predicate.

Cmn
Boolean
any()

Returns true if this map has at least one entry.

Cmn
inline Boolean
any(predicate: (K, Int) -> Boolean)

Returns true if at least one entry matches the given predicate.

Cmn
inline operator Boolean
contains(key: K)

Returns true if the specified key is present in this map, false otherwise.

Cmn
Boolean
containsKey(key: K)

Returns true if the specified key is present in this map, false otherwise.

Cmn
Boolean

Returns true if the specified value is present in this map, false otherwise.

Cmn
Int

Returns the number of entries in this map.

Cmn
inline Int
count(predicate: (K, Int) -> Boolean)

Returns the number of entries matching the given predicate.

Cmn
open operator Boolean
equals(other: Any?)

Compares the specified object other with this hash map for equality.

Cmn
inline Unit
forEach(block: (key, value: Int) -> Unit)

Iterates over every key/value pair stored in this map by invoking the specified block lambda.

Cmn
inline Unit
forEachKey(block: (key) -> Unit)

Iterates over every key stored in this map by invoking the specified block lambda.

Cmn
inline Unit
forEachValue(block: (value: Int) -> Unit)

Iterates over every value stored in this map by invoking the specified block lambda.

Cmn
operator Int
get(key: K)

Returns the value corresponding to the given key, or throws if the key is not present in the map.

Cmn
Int
getOrDefault(key: K, defaultValue: Int)

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

Cmn
inline Int
getOrElse(key: K, defaultValue: () -> Int)

Returns the value for the given key if the value is present.

Cmn
open Int

Returns the hash code value for this map.

Cmn
Boolean

Indicates whether this map is empty.

Cmn
Boolean

Returns true if this map is not empty.

Cmn
String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence
)

Creates a String from the entries, separated by separator and using prefix before and postfix after, if supplied.

Cmn
inline String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence,
    crossinline transform: (key, value: Int) -> CharSequence
)

Creates a String from the entries, separated by separator and using prefix before and postfix after, if supplied.

Cmn
Boolean

Returns true if this map has no entries.

Cmn
open String

Returns a string representation of this map.

Cmn

Inherited properties

From androidx.collection.ObjectIntMap
Int

Returns the number of key-value pairs that can be stored in this map without requiring internal storage reallocation.

Cmn
Int

Returns the number of key-value pairs in this map.

Cmn

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

clear

fun clear(): Unit

Removes all mappings from this map.

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.

Returns
Int

value previously associated with key or default if key was not present.

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): Unit

Removes the specified key and its associated value from the 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.