Maps

Collections of key-value pairs such that each unique key can have only one occurrence in the collection.

Import alias 'ads-js/maps'

This group provides implementations of different data-structures for fast search and access. It does not include common for such libraries HashMap/HashSet classes because they do already exist in JavaScript since ES6. Instead of replacing standard JS built-ins, classes presented here implement the same interfaces and may be used alongside with the first ones in the same client code.

This may sound confusing after what just have been said but one difference with the standard interface was introduced in get() method of all maps in ADSJS. Call to it throws an error instead of returning an undefined if key was not found. The necessity here is in fact that in TypeScript with strict types set on you will have to perform explicit type-checking for undefined each time even if you are not expecting to have such situations in your code in practice. Since convenience for TypeScript users is priority for this package so this change have been done.

Table of contents

SortedMap - a map that provides ordering on its keys. Keys are ordered by a comparator provided at map creation time or by default as strings.

MaximaSet - container which stores only pairs forming strictly increasing trend in both keys and values. This structure is based on SortedMap.

AVLTreeMap - sorted map based on an AVL binary tree structure.

SplayTreeMap - sorted map based on a splay binary tree structure.

RedBlackTreeMap - sorted map based on a red-black binary tree structure.

Last updated

Was this helpful?