Algorithms and data structures for JS/TS
  • Introduction
  • GETTING STARTED
    • TS
    • Node.js
    • ES Modules
    • Browsers
  • PUBLIC API
    • How to read
    • Linked lists
      • SinglyLinkedList
      • DoublyLinkedList
      • CircularlyLinkedList
    • Stacks and queues
      • LinkedStack
      • LinkedQueue
      • LinkedDeque
      • CircularQueue
      • CircularArrayBuffer
      • UnsortedPriorityQueue
      • SortedPriorityQueue
      • AdaptableHeapPriorityQueue
    • Maps
      • SortedMap
      • MaximaSet
      • AVLTreeMap
      • SplayTreeMap
      • RedBlackTreeMap
    • Trees
      • GeneralTree
      • LinkedBinaryTree
      • PreorderTreeTraversal
      • InorderTreeTraversal
      • PostorderTreeTraversal
      • EulerTourTreeTraversal
    • Searches
      • Binary search
      • Quick select
    • Text processing
      • Longest common subsequence
      • Boyer-Moore
      • Knuth-Morris-Pratt
    • Position
    • Locator
    • Comparators
  • CONTRIBUTION NOTES
    • How to contribute
    • Project structure
  • Changelog
Powered by GitBook
On this page

Was this helpful?

  1. PUBLIC API

Maps

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

PreviousAdaptableHeapPriorityQueueNextSortedMap

Last updated 5 years ago

Was this helpful?

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 / 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

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

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

- sorted map based on an AVL binary tree structure.

- sorted map based on a splay binary tree structure.

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

HashMap
HashSet
SortedMap
comparator
MaximaSet
AVLTreeMap
SplayTreeMap
RedBlackTreeMap