Skip to content
Buy me a coffee

IdentityHashMap

Defined in: src/map/IdentityHashMap.ts:66

A Map whose keys and values compare by reference (===, except NaN equals NaN; equals() and hashCode() are ignored). containsValue, remove(k, v), replace(k, old, new), entry and map equality, and the views all use that rule. Use it when the object itself matters, not its value, e.g. visited nodes in a graph walk.

Backed by a native Map, which uses exactly that key rule. null and undefined keys and values are allowed; iteration order is unspecified. get, put, containsKey and remove are O(1); iterators are fail-fast.

K

V

new IdentityHashMap<K, V>(): IdentityHashMap<K, V>

Defined in: src/map/IdentityHashMap.ts:76

Creates an empty map.

IdentityHashMap<K, V>

AbstractMap.constructor

new IdentityHashMap<K, V>(expectedMaxSize): IdentityHashMap<K, V>

Defined in: src/map/IdentityHashMap.ts:81

Creates an empty map; expectedMaxSize is a validated sizing hint only.

number

IdentityHashMap<K, V>

IllegalArgumentException if expectedMaxSize is negative or NaN

AbstractMap<K, V>.constructor

new IdentityHashMap<K, V>(map): IdentityHashMap<K, V>

Defined in: src/map/IdentityHashMap.ts:86

Creates a map with the mappings of map; keys that are distinct by reference stay distinct.

Map<K, V>

IdentityHashMap<K, V>

NullPointerException if map is null or undefined

AbstractMap<K, V>.constructor

modCount: number = 0

Defined in: src/map/IdentityHashMap.ts:70

Structural modification count; iterators compare against it.

[INSPECT](): string

Defined in: src/abstract/AbstractMap.ts:187

Node’s util.inspect hook: console.log prints the toString() form.

string

AbstractMap.[INSPECT]


[iterator](): IterableIterator<[K, V]>

Defined in: src/map/IdentityHashMap.ts:224

Returns a fail-fast iterator over the mappings as [key, value] pairs, in unspecified order.

IterableIterator<[K, V]>

AbstractMap.[iterator]


clear(): void

Defined in: src/map/IdentityHashMap.ts:193

Removes all mappings.

void

AbstractMap.clear


clone(): IdentityHashMap<K, V>

Defined in: src/map/IdentityHashMap.ts:95

Shallow copy of the same runtime class (subclass fields included).

IdentityHashMap<K, V>


compute(key, fn): V | null

Defined in: src/abstract/AbstractMap.ts:301

Puts fn(key, currentValueOrNull), or removes the mapping when fn returns null/undefined; returns the new value or null.

K

(key, value) => V | null | undefined

V | null

NullPointerException if fn is null

AbstractMap.compute


computeIfAbsent(key, fn): V | null

Defined in: src/abstract/AbstractMap.ts:268

If key has no value (absent or mapped to null), puts fn(key) unless it returns null/undefined; returns the current (possibly new) value, or null.

K

(key) => V | null | undefined

V | null

NullPointerException if fn is null

AbstractMap.computeIfAbsent


computeIfPresent(key, fn): V | null

Defined in: src/abstract/AbstractMap.ts:283

If key has a non-null value, replaces it with fn(key, value), or removes the mapping when fn returns null/undefined; returns the new value or null.

K

(key, value) => V | null | undefined

V | null

NullPointerException if fn is null

AbstractMap.computeIfPresent


containsKey(key): boolean

Defined in: src/map/IdentityHashMap.ts:128

Returns true if this map has a mapping for key (compared by reference), even if it maps to null. O(1).

unknown

boolean

AbstractMap.containsKey


containsValue(value): boolean

Defined in: src/map/IdentityHashMap.ts:133

Returns true if one or more keys map to value, compared by reference. O(n).

unknown

boolean

AbstractMap.containsValue


entrySet(): Set<MapEntry<K, V>>

Defined in: src/map/IdentityHashMap.ts:218

Returns a live view of the mappings. Its entries compare key and value by reference and setValue writes through; removing from it removes the mapping, and it does not support add (UnsupportedOperationException).

Set<MapEntry<K, V>>

AbstractMap.entrySet


equals(o): boolean

Defined in: src/map/IdentityHashMap.ts:243

Returns true if o is a map with the same mappings, keys and values both compared by reference.

unknown

boolean

AbstractMap.equals


forEach(action): void

Defined in: src/map/IdentityHashMap.ts:233

Calls action for each mapping, in iteration order.

(key, value) => void

void

NullPointerException if action is null

ConcurrentModificationException if action structurally modifies this map

AbstractMap.forEach


get(key): V | null

Defined in: src/map/IdentityHashMap.ts:122

Returns the value mapped to key, or null if there is none (or the key maps to null). O(1); key is found by reference, so an equal but distinct object is not found.

unknown

V | null

AbstractMap.get


getOrDefault(key, defaultValue): V

Defined in: src/abstract/AbstractMap.ts:206

Returns the value mapped to key, or defaultValue when there is no mapping (a mapping to null returns null).

unknown

V

V

AbstractMap.getOrDefault

getOrDefault(key, defaultValue): V | null

Defined in: src/abstract/AbstractMap.ts:209

Returns the value mapped to key, or defaultValue when there is no mapping (a mapping to null returns null).

unknown

V | null

V | null

AbstractMap.getOrDefault


hashCode(): number

Defined in: src/map/IdentityHashMap.ts:260

Returns the sum over all entries of the key’s identity hash code XOR the value’s hashCode(), in 32-bit arithmetic, so it is consistent with reference equality.

number

AbstractMap.hashCode


isEmpty(): boolean

Defined in: src/map/IdentityHashMap.ts:110

Returns true if this map has no mappings. O(1).

boolean

AbstractMap.isEmpty


keySet(): Set<K>

Defined in: src/map/IdentityHashMap.ts:202

Returns a live view of the keys, compared by reference. Removing from it removes the mapping; it does not support add (UnsupportedOperationException).

Set<K>

AbstractMap.keySet


merge(key, value, fn): V | null

Defined in: src/abstract/AbstractMap.ts:318

Puts value if key has no value (absent or mapped to null), otherwise fn(oldValue, value); removes the mapping when fn returns null/undefined. Returns the new value or null.

K

V

(oldValue, value) => V | null | undefined

V | null

NullPointerException if fn or value is null

AbstractMap.merge


put(key, value): V | null

Defined in: src/map/IdentityHashMap.ts:143

Maps key to value, replacing any previous value. O(1). A key that is not === to an existing key adds a new mapping, even if it equals() one.

K

V

V | null

the previous value, or null if there was no mapping

AbstractMap.put


putAll(m): void

Defined in: src/abstract/AbstractMap.ts:119

Calls put for each mapping of a snapshot of m’s entries.

Map<K, V>

void

NullPointerException if m is null

UnsupportedOperationException if put is not supported and m is not empty

AbstractMap.putAll


putIfAbsent(key, value): V | null

Defined in: src/abstract/AbstractMap.ts:244

If key has no value (absent or mapped to null), puts value and returns the previous value; else returns the current value.

K

V

V | null

AbstractMap.putIfAbsent


remove(key): V | null

Defined in: src/map/IdentityHashMap.ts:155

Removes the mapping for key (compared by reference), if present. O(1).

unknown

V | null

the removed value, or null if there was no mapping

AbstractMap.remove

remove(key, value): boolean

Defined in: src/map/IdentityHashMap.ts:160

Removes the mapping for key only if it is currently mapped to value, both compared by reference. O(1).

unknown

unknown

boolean

true if the mapping was removed

AbstractMap.remove


replace(key, value): V | null

Defined in: src/map/IdentityHashMap.ts:175

Replaces the value for key (compared by reference) only if key currently has a mapping (even to null). O(1).

K

V

V | null

the previous value, or null if there was no mapping

AbstractMap.replace

replace(key, oldValue, newValue): boolean

Defined in: src/map/IdentityHashMap.ts:181

Replaces the value for key with newValue only if it is currently mapped to oldValue, both compared by reference. O(1).

K

V

V

boolean

true if the value was replaced

AbstractMap.replace


replaceAll(fn): void

Defined in: src/abstract/AbstractMap.ts:234

Replaces each value with fn(key, value), through the entries’ setValue.

(key, value) => V

void

NullPointerException if fn is null

UnsupportedOperationException if the entries do not support setValue

AbstractMap.replaceAll


size(): number

Defined in: src/map/IdentityHashMap.ts:105

Returns the number of mappings. O(1).

number

AbstractMap.size


toString(): string

Defined in: src/abstract/AbstractMap.ts:191

Returns {k1=v1, k2=v2} in entry-set order; a key or value that is this map prints as (this Map).

string

AbstractMap.toString


values(): Collection<V>

Defined in: src/map/IdentityHashMap.ts:210

Returns a live view of the values; its contains and remove compare by reference. Removing from it removes the mapping; it does not support add (UnsupportedOperationException).

Collection<V>

AbstractMap.values