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
  • new MaximaSet()
  • length
  • add()
  • getBest()
  • clear()
  • getFirst()
  • getLast()
  • isEmpty()
  • [Symbol.iterator]()

Was this helpful?

  1. PUBLIC API
  2. Maps

MaximaSet

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

new MaximaSet()

/**
 * Creates an instance of MaximaSet.
 *
 * @param iterable Iterable of X, Y pairs to create the new maxima set with.
 * @param compareX Comparison function for pairs sorting by X values. Xs are compared as numbers by default.
 * @param compareY Comparison function for pairs sorting by Y values. Ys are compared as numbers by default.
 */
constructor(
  iterable: Iterable<[X, Y]> = [],
  protected compareX: CompareFunc<X> = compareAsNumbers,
  protected compareY: CompareFunc<Y> = compareAsNumbers,
)

length

/**
 * Number of pairs in the set.
 *
 * @readonly
 */
get length(): number;

add()

/**
 * Adds X, Y pair to the maxima set if there is no better pair in it.
 *
 * @param x X value.
 * @param y Y value.
 */
add(x: X, y: Y)

getBest()

/**
 * Gets X, Y pair with largest X not exceeding the specified value.
 *
 * @param x X value.
 * @returns X, Y pair or undefined if the set is empty.
 */
getBest(x: X): [X, Y] | undefined

clear()

/**
 * Clears the set.
 */
clear(): void;

getFirst()

/**
 * Gets X, Y pair with least X.
 *
 * @returns X, Y pair or undefined if the set is empty.
 */
getFirst(): [X, Y] | undefined;

getLast()

/**
 * Gets X, Y pair with greatest X.
 *
 * @returns X, Y pair or undefined if the set is empty.
 */
getLast(): [X, Y] | undefined;

isEmpty()

/**
 * Checks whether the set is empty or not.
 *
 * @returns TRUE if the map is empty, FALSE otherwise.
 */
isEmpty(): boolean;

[Symbol.iterator]()

[Symbol.iterator](): IterableIterator<[X, Y]>
PreviousSortedMapNextAVLTreeMap

Last updated 5 years ago

Was this helpful?