Skip to content

FuzzyMap

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:39

A map whose keys match after a caller-supplied normalisation.

Case-insensitive lookup, accent folding, whitespace collapsing, phonetic keys — all the same structure with a different function, rather than one class per normalisation strategy. normalize is applied to every key on the way in and to every query on the way out; whatever it maps together is together.

The first key to claim a normalised slot is the one keys() reports, and a later set under an equivalent key updates the value without replacing the stored key. So a map normalising by lower case, given "Foo" then "FOO", holds one entry keyed "Foo" — the original spelling survives, which is what makes it usable for display.

Time complexity: O(1) plus the cost of normalize, for every operation.

K

The key type as callers see it.

V extends DefinedValue

The value type.

new FuzzyMap<K, V>(iterable, options): FuzzyMap<K, V>

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:43

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

FuzzyMapOptions<K>

FuzzyMap<K, V>

[iterator](): Iterator<readonly [K, V]>

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:56

Iterator<readonly [K, V]>

IMap.[iterator]


clear(): void

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:64

Removes all elements from the collection.

void

IMap.clear


count(): number

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:60

The number of elements in the collection.

A method, not a getter: its async counterpart needs a round trip to the backing store, and a member must have the same shape in both.

number

IMap.count


delete(key): boolean

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:91

O(1) plus normalize.

K

boolean

IMap.delete


entries(): IterableIterator<readonly [K, V]>

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:110

In first-insertion order, each key in its original form.

IterableIterator<readonly [K, V]>

IMap.entries


get(key): V | undefined

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:69

O(1) plus normalize.

K

V | undefined

IMap.get


has(key): boolean

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:86

O(1) plus normalize.

K

boolean

IMap.has


keys(): IterableIterator<K>

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:96

The stored keys, in their original form, in first-insertion order.

IterableIterator<K>

IMap.keys


set(key, value): void

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:74

O(1) plus normalize. Keeps the key already stored, if any.

K

V

void

IMap.set


storedKey(key): K | undefined

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:122

The key actually stored for whatever key normalises to.

Answers “which spelling won” without going through keys(): the stored key and the query can differ, which is the whole point of this type.

K

K | undefined


values(): IterableIterator<V>

Defined in: packages/data/src/fuzzy/fuzzy-map.ts:103

In first-insertion order.

IterableIterator<V>

IMap.values