IntObjectMap

internal class IntObjectMap<V>

A highly optimized, primitive-key map implementation that maps primitive Int keys to object values.

This implementation avoids the memory and performance overhead of autoboxing integers into java.lang.Integer objects, which occurs when using standard collections like HashMap<Int, V>. It utilizes open addressing with linear probing for fast lookups and insertions.

Note: The key 0 is reserved internally as an empty slot indicator and cannot be used.

Type Parameters

V

the type of values maintained by this map

Constructors

Link copied to clipboard
constructor(capacity: Int = 128)
constructor(other: IntObjectMap<V>)

Properties

Link copied to clipboard
Link copied to clipboard
val size: Int
Link copied to clipboard
val values: List<V>

Functions

Link copied to clipboard

Whether key has a value. Since the map holds no nulls, this is get(key) != null.

Link copied to clipboard
fun forEach(action: (key: Int, value: V) -> Unit)

Runs action for every entry, walking the table directly so that nothing is allocated to iterate - no entry objects, no boxed keys.

Link copied to clipboard
operator fun get(key: Int): V?

The value stored under key, or null if there is none. A lookup for 0 is null rather than an error, so the reserved key reads as absent on the way out even though it is refused on the way in.

Link copied to clipboard

Whether the map holds nothing.

Link copied to clipboard

Whether the map holds anything.

Link copied to clipboard
fun put(key: Int, value: V)

Stores value under key, growing and rehashing the table when it passes its load factor.

Link copied to clipboard
operator fun set(key: Int, value: V)

put, written as map[key] = value.