IntMap

ceramic.IntMap (Class)

An object map that uses integers as key.

IntMap provides efficient storage and retrieval of values indexed by integers. It's optimized for performance with support for null values and optional iteration.

Features:

  • O(1) average case get/set operations
  • Support for null values with proper handling
  • Optional iteration support with iterableKeys
  • Automatic resizing of internal storage
  • Memory-efficient storage using vectors

The implementation uses IntIntMap internally to map keys to value indices, with special handling for null values to distinguish between "no value" and "null value" cases.

Example usage:

var map = new IntMap<String>();
map.set(42, "hello");
map.set(10, null); // Null values are supported
trace(map.get(42)); // "hello"
trace(map.exists(10)); // true (even though value is null)

Instance Members

iterableKeys: Array<Int>

When this map is marked as iterable, this array will contain every key.


values: haxe.ds.Vector<ceramic.IntMap.V>

Values as they are stored. Can be used to iterate on values directly, but can contain null values.


get(key: Int): ceramic.IntMap.V

Gets the value associated with the given key.

Name Type Description
key Int The integer key
Returns Description
ceramic.IntMap.V The value, or null if key doesn't exist

getInline(key: Int): ceramic.IntMap.V
Name Type
key Int
Returns
ceramic.IntMap.V

exists(key: Int): Bool

Checks if a key exists in the map.

Name Type Description
key Int The integer key to check
Returns Description
Bool True if the key exists (even if value is null)

existsInline(key: Int): Bool
Name Type
key Int
Returns
Bool

set(key: Int, value: ceramic.IntMap.V): Void

Sets a value for the given key.

Name Type Description
key Int The integer key
value ceramic.IntMap.V The value to set (can be null)

remove(key: Int): Void

Removes a key-value pair from the map.

Name Type Description
key Int The integer key to remove

copy(): IntMap<ceramic.IntMap.V>

Creates a shallow copy of this map.

Returns Description
IntMap<ceramic.IntMap.V> A new IntMap with the same key-value pairs

clear(): Void

Clears all key-value pairs from the map.


iterator(): IntMapIterator<ceramic.IntMap.V>

Returns an iterator over the values in this map. Note: Map must be created with iterable=true

Returns
IntMapIterator<ceramic.IntMap.V>

keys(): IntMapKeyIterator<ceramic.IntMap.V>

Returns an iterator over the keys in this map. Note: Map must be created with iterable=true

Returns
IntMapKeyIterator<ceramic.IntMap.V>

keyValueIterator(): IntMapKeyValueIterator<ceramic.IntMap.V>

Returns an iterator over key-value pairs in this map. Note: Map must be created with iterable=true

Returns
IntMapKeyValueIterator<ceramic.IntMap.V>

new(?size: Int = 16, ?fillFactor: Float = 0.5, ?iterable: Bool = false): Void

Creates a new IntMap.

Name Type Default Description
size Int 16 Initial capacity (default: 16)
fillFactor Float 0.5 Fill factor for internal map (default: 0.5)
iterable Bool false Enable iteration support (default: false)

Private Members

NO_VALUE: Int

NULL_VALUE: Int

RESERVED_GAP: Int

RET_NULL: Any

nextFreeIndex: Int

initialSize: Int

initialFillFactor: Float

resizeValues(targetSize: Int): Void
Name Type
targetSize Int