BidirectionalMap
此内容尚不支持你的语言。
Defined in: src/util/BidirectionalMap.ts:57
Type Parameters
Section titled “Type Parameters”K
V
Implements
Section titled “Implements”Map<K,V>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”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.
Parameters
Section titled “Parameters”entries?
Section titled “entries?”Iterable<readonly [K, V], any, any> | null
Returns
Section titled “Returns”BidirectionalMap<K, V>
Accessors
Section titled “Accessors”[toStringTag]
Section titled “[toStringTag]”Get Signature
Section titled “Get Signature”get [toStringTag]():
string
Defined in: src/util/BidirectionalMap.ts:320
Makes Object.prototype.toString.call(…) report [object BidirectionalMap].
Returns
Section titled “Returns”string
Implementation of
Section titled “Implementation of”Map.[toStringTag]
keySize
Section titled “keySize”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get size():
number
Defined in: src/util/BidirectionalMap.ts:82
Number of pairs. Both directions always agree on it.
Returns
Section titled “Returns”number
Implementation of
Section titled “Implementation of”Map.size
valueSize
Section titled “valueSize”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”[iterator]():
MapIterator<[K,V]>
Defined in: src/util/BidirectionalMap.ts:315
[key, value] pairs — makes the map spreadable and for…of-able.
Returns
Section titled “Returns”MapIterator<[K, V]>
Implementation of
Section titled “Implementation of”Map.[iterator]
clear()
Section titled “clear()”clear():
void
Defined in: src/util/BidirectionalMap.ts:191
Drops every pair.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Map.clear
delete()
Section titled “delete()”delete(
key):boolean
Defined in: src/util/BidirectionalMap.ts:173
Removes the pair held by key, from both directions. true if there was one.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”Map.delete
deleteValue()
Section titled “deleteValue()”deleteValue(
value):boolean
Defined in: src/util/BidirectionalMap.ts:182
Removes the pair held by value, from both directions. true if there was one.
Parameters
Section titled “Parameters”V
Returns
Section titled “Returns”boolean
entries()
Section titled “entries()”entries():
MapIterator<[K,V]>
Defined in: src/util/BidirectionalMap.ts:209
[key, value] pairs, in insertion order.
Returns
Section titled “Returns”MapIterator<[K, V]>
Implementation of
Section titled “Implementation of”Map.entries
forEach()
Section titled “forEach()”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.
Parameters
Section titled “Parameters”callback
Section titled “callback”(value, key, map) => void
thisArg?
Section titled “thisArg?”unknown
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Map.forEach
get(
key):V|undefined
Defined in: src/util/BidirectionalMap.ts:149
The value bound to key, or undefined.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”V | undefined
Implementation of
Section titled “Implementation of”Map.get
getKey()
Section titled “getKey()”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.
Parameters
Section titled “Parameters”V
Returns
Section titled “Returns”K | undefined
getOrInsert()
Section titled “getOrInsert()”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.
Parameters
Section titled “Parameters”K
defaultValue
Section titled “defaultValue”V
Returns
Section titled “Returns”V
getOrInsertComputed()
Section titled “getOrInsertComputed()”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.
Parameters
Section titled “Parameters”K
callback
Section titled “callback”(key) => V
Returns
Section titled “Returns”V
getOrInsertComputedKey()
Section titled “getOrInsertComputedKey()”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.
Parameters
Section titled “Parameters”V
callback
Section titled “callback”(value) => K
Returns
Section titled “Returns”K
getOrInsertKey()
Section titled “getOrInsertKey()”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.
Parameters
Section titled “Parameters”V
defaultKey
Section titled “defaultKey”K
Returns
Section titled “Returns”K
has(
key):boolean
Defined in: src/util/BidirectionalMap.ts:163
Whether key is bound. Distinguishes “bound to undefined” from “absent”.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”Map.has
hasValue()
Section titled “hasValue()”hasValue(
value):boolean
Defined in: src/util/BidirectionalMap.ts:168
Whether value is bound. Matches by SameValueZero, like getKey.
Parameters
Section titled “Parameters”V
Returns
Section titled “Returns”boolean
inverse()
Section titled “inverse()”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.
Returns
Section titled “Returns”BidirectionalMap<V, K>
keys()
Section titled “keys()”keys():
MapIterator<K>
Defined in: src/util/BidirectionalMap.ts:214
The keys, in insertion order.
Returns
Section titled “Returns”MapIterator<K>
Implementation of
Section titled “Implementation of”Map.keys
reverseEntries()
Section titled “reverseEntries()”reverseEntries():
MapIterator<[V,K]>
Defined in: src/util/BidirectionalMap.ts:224
[value, key] pairs — the reverse direction, in its own insertion order.
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”this
Implementation of
Section titled “Implementation of”Map.set
toJSON()
Section titled “toJSON()”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.
Returns
Section titled “Returns”BidirectionalMapJson<K, V>
trySet()
Section titled “trySet()”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.
Parameters
Section titled “Parameters”K
V
Returns
Section titled “Returns”boolean
values()
Section titled “values()”values():
MapIterator<V>
Defined in: src/util/BidirectionalMap.ts:219
The values, in insertion order. Every one is unique, so this is a set.
Returns
Section titled “Returns”MapIterator<V>
Implementation of
Section titled “Implementation of”Map.values
fromJSON()
Section titled “fromJSON()”
staticfromJSON<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.
Type Parameters
Section titled “Type Parameters”K
V
Parameters
Section titled “Parameters”BidirectionalMapJson<K, V>
Returns
Section titled “Returns”BidirectionalMap<K, V>
