Ir al contenido
Español

BidirectionalMap

Esta página aún no está disponible en tu idioma.

Defined in: src/util/BidirectionalMap.ts:57

K

V

  • Map<K, V>

new BidirectionalMap<K, V>(entries?): BidirectionalMap<K, V>

Defined in: src/util/BidirectionalMap.ts:73

Builds an empty map, or one seeded from entries the way new Map(…) seeds itself. Seeding goes through set, so a duplicate key or a duplicate value in the input resolves last-wins rather than corrupting the invariant.

Iterable<readonly [K, V], any, any> | null

BidirectionalMap<K, V>

get [toStringTag](): string

Defined in: src/util/BidirectionalMap.ts:320

Makes Object.prototype.toString.call(…) report [object BidirectionalMap].

string

Map.[toStringTag]


get keySize(): number

Defined in: src/util/BidirectionalMap.ts:95

Number of distinct keys — always the same number as size, because the relation is 1:1.

It carries no information size does not, and exists for symmetry with BidirectionalMultiMap.leftSize, where the two counts genuinely differ: moving between the two types should not require remembering which one has the accessor.

number


get size(): number

Defined in: src/util/BidirectionalMap.ts:82

Number of pairs. Both directions always agree on it.

number

Map.size


get valueSize(): number

Defined in: src/util/BidirectionalMap.ts:108

Number of distinct values — the mirror of keySize, and again the same number as size.

Reads reverse rather than forward deliberately. An accessor that reads the direction it names still tells the truth if the invariant ever breaks, where an alias for forward.size would hide the break behind the count it is supposed to corroborate.

number

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

Defined in: src/util/BidirectionalMap.ts:315

[key, value] pairs — makes the map spreadable and for…of-able.

MapIterator<[K, V]>

Map.[iterator]


clear(): void

Defined in: src/util/BidirectionalMap.ts:191

Drops every pair.

void

Map.clear


delete(key): boolean

Defined in: src/util/BidirectionalMap.ts:173

Removes the pair held by key, from both directions. true if there was one.

K

boolean

Map.delete


deleteValue(value): boolean

Defined in: src/util/BidirectionalMap.ts:182

Removes the pair held by value, from both directions. true if there was one.

V

boolean


entries(): MapIterator<[K, V]>

Defined in: src/util/BidirectionalMap.ts:209

[key, value] pairs, in insertion order.

MapIterator<[K, V]>

Map.entries


forEach(callback, thisArg?): void

Defined in: src/util/BidirectionalMap.ts:204

Iterates in insertion order, like Map.forEach.

The third callback argument is this map, not the internal forward one. Handing out the internal map would let a callback mutate one direction directly and leave the other stale — the invariant has to be unreachable from outside, not merely undocumented.

(value, key, map) => void

unknown

void

Map.forEach


get(key): V | undefined

Defined in: src/util/BidirectionalMap.ts:149

The value bound to key, or undefined.

K

V | undefined

Map.get


getKey(value): K | undefined

Defined in: src/util/BidirectionalMap.ts:158

The key bound to value, or undefined — the whole point of the type. Matches by SameValueZero, so two structurally equal objects are two different values.

V

K | undefined


getOrInsert(key, defaultValue): V

Defined in: src/util/BidirectionalMap.ts:245

The value bound to key, inserting defaultValue first if there is none. Inserting goes through set, so it can displace whichever key held defaultValue before.

K

V

V


getOrInsertComputed(key, callback): V

Defined in: src/util/BidirectionalMap.ts:255

The value bound to key, computing and inserting one if there is none. callback runs at most once, and only on the inserting path.

K

(key) => V

V


getOrInsertComputedKey(value, callback): K

Defined in: src/util/BidirectionalMap.ts:278

The key bound to value, computing and inserting one if there is none. callback runs at most once — it typically mints an identifier, so calling it twice would hand back one that was never stored.

V

(value) => K

K


getOrInsertKey(value, defaultKey): K

Defined in: src/util/BidirectionalMap.ts:267

The key bound to value, inserting defaultKey first if there is none. The mirror of getOrInsert — note it returns a key, not a value.

V

K

K


has(key): boolean

Defined in: src/util/BidirectionalMap.ts:163

Whether key is bound. Distinguishes “bound to undefined” from “absent”.

K

boolean

Map.has


hasValue(value): boolean

Defined in: src/util/BidirectionalMap.ts:168

Whether value is bound. Matches by SameValueZero, like getKey.

V

boolean


inverse(): BidirectionalMap<V, K>

Defined in: src/util/BidirectionalMap.ts:233

The same map, read the other way round — a view over the same storage, not a copy. A write on either side is visible from the other, and inverse().inverse() is another view with the original orientation.

BidirectionalMap<V, K>


keys(): MapIterator<K>

Defined in: src/util/BidirectionalMap.ts:214

The keys, in insertion order.

MapIterator<K>

Map.keys


reverseEntries(): MapIterator<[V, K]>

Defined in: src/util/BidirectionalMap.ts:224

[value, key] pairs — the reverse direction, in its own insertion order.

MapIterator<[V, K]>


set(key, value): this

Defined in: src/util/BidirectionalMap.ts:117

Binds key to value, evicting whatever held either side before — see the note on displacement in the class docs. Use BidirectionalMap.trySet to refuse instead of evicting.

K

V

this

Map.set


toJSON(): BidirectionalMapJson<K, V>

Defined in: src/util/BidirectionalMap.ts:291

Wire shape — the forward pairs only, tagged so a decoder can tell what it is. Honoured by JSON.stringify, which is what carries the map over the cluster wire; persistence stores use the richer JsonTree tag instead and never reach this method.

BidirectionalMapJson<K, V>


trySet(key, value): boolean

Defined in: src/util/BidirectionalMap.ts:137

Binds key to value only when that removes nothing: false — and no mutation at all — if either side is already bound to something else. Re-writing a pair that is already present is a no-op and returns true.

K

V

boolean


values(): MapIterator<V>

Defined in: src/util/BidirectionalMap.ts:219

The values, in insertion order. Every one is unique, so this is a set.

MapIterator<V>

Map.values


static fromJSON<K, V>(json): BidirectionalMap<K, V>

Defined in: src/util/BidirectionalMap.ts:304

Rebuilds a map from toJSON output, restoring the reverse direction from the forward pairs.

The payload is an array of pairs rather than an object, which is why this decoder needs none of the __proto__ guards a peer-facing object decoder does: keys go into a Map, where '__proto__' is an ordinary key and reaches no prototype setter.

K

V

BidirectionalMapJson<K, V>

BidirectionalMap<K, V>