Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SortedSet<T>

A sorted set.

Type parameters

  • T

Hierarchy

  • SortedSet

Implements

  • Set<T>

Index

Constructors

constructor

  • new SortedSet<T>(compare?: (a: T, b: T) => number): SortedSet<T>
  • Type parameters

    • T

    Parameters

    • compare: (a: T, b: T) => number = ...
        • (a: T, b: T): number
        • Parameters

          • a: T
          • b: T

          Returns number

    Returns SortedSet<T>

Properties

[Symbol.toStringTag]

[Symbol.toStringTag]: string = 'SortedSet'

Private compare

compare: (a: T, b: T) => number

Type declaration

    • (a: T, b: T): number
    • Parameters

      • a: T
      • b: T

      Returns number

Private Optional root

root: undefined | WBTNode<{ value: T }>

Accessors

size

  • get size(): number
  • The number of distinct elements in the set.

    Returns number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): Generator<T, any, unknown>
  • Iterates over the values in the set in sorted order.

    Returns Generator<T, any, unknown>

add

  • Inserts a value into the set.

    Parameters

    • value: T

      The value to insert.

    Returns SortedSet<T>

bisect

  • bisect(value: T): number
  • Calculates the minimum would-be index in the sorted set if the value was inserted, or the actual index if the value is already in the set.

    Parameters

    • value: T

    Returns number

clear

  • clear(): void
  • Removes all elements from the SortedSet object.

    Returns void

delete

  • delete(value: T): boolean
  • Removes a value from the set and returns a boolean determining whether the removal was successful. (the value was or wasn't in the tree beforehand)

    Parameters

    • value: T

      The value to remove

    Returns boolean

entries

  • entries(): IterableIterator<[T, T]>
  • Returns a new iterator object that contains an array of [value, value] for each element in the Set object, in sorted order.

    This is similar to the Map object, so that each entry's key is the same as its value for a SortedSet.

    Returns IterableIterator<[T, T]>

forEach

  • forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: unknown): void
  • Calls callbackfn once for each value present in the SortedSet object, in sorted order. If a thisArg parameter is provided, it will be used as the this value for each invocation of callbackfn.

    Parameters

    • callbackfn: (value: T, value2: T, set: Set<T>) => void

      Function to execute for each element.

        • (value: T, value2: T, set: Set<T>): void
        • Parameters

          • value: T
          • value2: T
          • set: Set<T>

          Returns void

    • Optional thisArg: unknown

      Value to use as this when executing callbackfn.

    Returns void

get

  • get(idx: number): undefined | T
  • Returns the value at the given index in the sorted order. (0-indexed)

    If the index is invalid, returns undefined.

    Parameters

    • idx: number

      The index to lookup

    Returns undefined | T

has

  • has(value: T): boolean
  • Determines whether the value is in the set.

    Parameters

    • value: T

    Returns boolean

keys

  • keys(): IterableIterator<T>
  • Returns a new iterator object that yields the values for each element in the SortedSet object in sorted order. (For SortedSets, this is the same as the values() method.)

    Returns IterableIterator<T>

values

  • values(): IterableIterator<T>
  • Returns a new iterator object that yields the values for each element in the SortedSet object in sorted order. (For SortedSets, this is the same as the keys() method.)

    Returns IterableIterator<T>

Generated using TypeDoc