A collection of various useful container datastructures.
npm install @sbcohen/containersHere are some useful container datastructures written in Typescript.
Map type is if you need a| Method | Description |
|---------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| new HAMT() | Construct a new HAMT. |
| size: number | Get the number of elements in the map. |
| get(key: string): V \| undefined | Retrieve a value from the map (or undefined if no such key exists). |
| set(key: string, value: V): HAMT | Associate a key-value pair in the map, returning a new map, containing the given key. If the key already exists in the map, its value is replaced in the resulting map. |
Map type is that you can define your own| Method | Description |
|----------------------------------------|------------------------------------------------------------------------------------------------------------|
| new RBTree(compareFn?: CompareFn | Construct a new RBTree, optionally providing a comparison function on keys. |
| has(key: K): boolean | Check if the map contains a value with the given key. |
| get(key: K): V \| undefined | Retrieve a value by its key, returning undefined if the value isn't in the map. |
| set(key: K, value: V): RBTree | Associate a key with a value. If the key is already associated with a value, the value is updated. |
| delete(key: K): boolean | Delete a key and its associated value from the map. If the key does not exist in the map, this is a no-op. |
| size: number | Get the number of elements in the map. |
| *entries(): IterableIterator<[K, V]> | Iterate over the keys and values of the map from least to greatest key. |
search method which returns all of the values which intersect a| Method | Description |
|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| new IntervalTree() | Construct a new IntervalTree |
| has(interval: Interval) | Check if the interval tree contains a value with the given interval. |
| get(interval: Interval): V \| undefined | Retrieve a value by its interval, returning undefined if the value isn't in the map. |
| set(interval: Interval, value: V): IntervalTree | Associate an interval with a value. If the interval already exists within the map, then the value at the interval is replaced. |
| delete(interval: Interval): boolean | Delete an interval and its associated value from the tree. If the interval does not exist in the map, this is a no-op. |
| *search(query: Interval): IterableIterator | Find all of the values which intersect the given interval. |
| size: number | Get the number of elements in the map. |
| *entries(): IterableIterator<[K, V]> | Iterate over the keys and values of the map from least to greatest key. |
Feedback and pull requests are welcome!