ObjectLongMap
-
Cmn
sealed class ObjectLongMap<K : Any?>
MutableObjectLongMap |
|
ObjectLongMap is a container with a Map-like interface for keys with reference types and Long 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 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.
This implementation is read-only and only allows data to be queried. A mutable implementation is provided by MutableObjectLongMap.
| See also | |
|---|---|
MutableObjectLongMap |
|
ScatterMap |
Summary
Protected constructors |
|
|---|---|
<K : Any?> ObjectLongMap() |
Cmn
|
Public functions |
||
|---|---|---|
inline Boolean |
Returns true if all entries match the given |
Cmn
|
Boolean |
any()Returns |
Cmn
|
inline Boolean |
Returns true if at least one entry matches the given |
Cmn
|
inline operator Boolean |
contains(key: K)Returns true if the specified |
Cmn
|
Boolean |
containsKey(key: K)Returns true if the specified |
Cmn
|
Boolean |
containsValue(value: Long)Returns true if the specified |
Cmn
|
Int |
count()Returns the number of entries in this map. |
Cmn
|
inline Int |
Returns the number of entries matching the given |
Cmn
|
open operator Boolean |
Compares the specified object |
Cmn
|
inline Unit |
Iterates over every key/value pair stored in this map by invoking the specified |
Cmn
|
inline Unit |
forEachKey(block: (key) -> Unit)Iterates over every key stored in this map by invoking the specified |
Cmn
|
inline Unit |
forEachValue(block: (value: Long) -> Unit)Iterates over every value stored in this map by invoking the specified |
Cmn
|
operator Long |
get(key: K)Returns the value corresponding to the given |
Cmn
|
Long |
getOrDefault(key: K, defaultValue: Long)Returns the value to which the specified |
Cmn
|
inline Long |
Returns the value for the given |
Cmn
|
open Int |
hashCode()Returns the hash code value for this map. |
Cmn
|
Boolean |
isEmpty()Indicates whether this map is empty. |
Cmn
|
Boolean |
Returns |
Cmn
|
String |
joinToString(Creates a String from the entries, separated by |
Cmn
|
inline String |
joinToString(Creates a String from the entries, separated by |
Cmn
|
Boolean |
none()Returns |
Cmn
|
open String |
toString()Returns a string representation of this map. |
Cmn
|
Public properties |
||
|---|---|---|
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
|
Protected constructors
Public functions
all
inline fun all(predicate: (K, Long) -> Boolean): Boolean
Returns true if all entries match the given predicate.
any
inline fun any(predicate: (K, Long) -> Boolean): Boolean
Returns true if at least one entry matches the given predicate.
contains
inline operator fun contains(key: K): Boolean
Returns true if the specified key is present in this map, false otherwise.
containsKey
fun containsKey(key: K): Boolean
Returns true if the specified key is present in this map, false otherwise.
containsValue
fun containsValue(value: Long): Boolean
Returns true if the specified value is present in this map, false otherwise.
count
inline fun count(predicate: (K, Long) -> Boolean): Int
Returns the number of entries matching the given predicate.
equals
open operator fun equals(other: Any?): Boolean
Compares the specified object other with this hash map for equality. The two objects are considered equal if other:
-
Is a
ObjectLongMap -
Has the same
sizeas this map -
Contains key/value pairs equal to this map's pair
forEach
inline fun forEach(block: (key, value: Long) -> Unit): Unit
Iterates over every key/value pair stored in this map by invoking the specified block lambda.
forEachKey
inline fun forEachKey(block: (key) -> Unit): Unit
Iterates over every key stored in this map by invoking the specified block lambda.
forEachValue
inline fun forEachValue(block: (value: Long) -> Unit): Unit
Iterates over every value stored in this map by invoking the specified block lambda.
get
operator fun get(key: K): Long
Returns the value corresponding to the given key, or throws if the key is not present in the map.
| Throws | |
|---|---|
kotlin.NoSuchElementException |
when |
getOrDefault
fun getOrDefault(key: K, defaultValue: Long): Long
Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
getOrElse
inline fun getOrElse(key: K, defaultValue: () -> Long): Long
Returns the value for the given key if the value is present. Otherwise, returns the result of the defaultValue function.
hashCode
open fun hashCode(): Int
Returns the hash code value for this map. The hash code the sum of the hash codes of each key/value pair.
joinToString
fun joinToString(
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "..."
): String
Creates a String from the entries, separated by separator and using prefix before and postfix after, if supplied.
When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.
joinToString
inline fun joinToString(
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
crossinline transform: (key, value: Long) -> CharSequence
): String
Creates a String from the entries, separated by separator and using prefix before and postfix after, if supplied. Each entry is created with transform.
When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.