MultiKeyMap
Table of Contents
Introduction
This library is a map implementation that supports multiple keys. Also known as a Trie
Note that the license for this library is AGPL-3.0-only. You should know what that means before using this library. If you would like an exception to this license per section 7 contact the author.
Library Installation
As a dependency run the command:
npm install @final-hill/multi-key-map
You can also use a specific version:
npm install @final-hill/multi-key-map@1.0.0
For use in a webpage:
<script src="https://unpkg.com/@final-hill/multi-key-map"></script>
With a specific version:
<script src="https://unpkg.com/@final-hill/multi-key-map@1.0.0></script>
Usage
After installation the library can be imported as such:
import MultiKeyMap from '@final-hill/multi-key-map';
The interface is similar to the standard Map, but extended to support multiple keys:
interface MultiKeyMap<KS extends unknown[], V> {
*[Symbol.iterator](): IterableIterator<[KS, V]>
constructor(entries?: readonly (readonly [...KS, V])[] | null)
clear(): void
delete(...keys: KS): boolean
*entries(): IterableIterator<[KS, V]>
forEach(callbackfn: (value: V, keys: KS, multiKeyMap: MultiKeyMap<KS, V>) => void, thisArg?: any): void
get(...keys: KS): V | undefined
has(...keys: KS): boolean
*keys(): IterableIterator<KS>
set(...keysValue: [...KS, V]): this
get size(): number
toString(): string
*values(): IterableIterator<V>
}
For examples view src/index.test.ts