A SortedSet uses a Comparator for sorting the values and checking for equality.

Example

Add, delete and iterate

const sortedSet = new SortedSet(numberComparator);
sortedSet.add(2);

const otherSortedSet = new SortedSet(numberComparator);
otherSortedSet.add(2);
otherSortedSet.add(3);
otherSortedSet.add(1);

sortedSet.add(otherSortedSet);

sortedSet.delete(1);

const result = sortedSet.has(2);
console.log(result); // true

for(const value of sortedSet) {
console.log(value); // 2, 3
}

Type Parameters

Hierarchy

Constructors

Properties

#comparator: Comparator<T>
#values: T[]
[toStringTag]: string = "SortedSet"

See

Set[Symbol.toStringTag]

Accessors

Methods

  • Returns the value at the specified index.

    Returns

    the element at the specified index, or undefined if out of bounds

    Parameters

    • index: number

      the index of the element to get

    Returns undefined | T

  • Removes values from this SortedSet if it does contain equal values. Values are considered equal if the Comparator returns 0.

    Mutation

    Example

    Remove values

    const sortedSet = new SortedSet(numberComparator, [1, 2, 3, 4, 5]);

    sortedSet.delete(new SortedSet(numberComparator, [0, 1, 2, 5]))

    console.log([...sortedSet.values()]); // [3, 4]

    Returns

    true if this SortedSet has ben modified, otherwise false

    Parameters

    • value: T

    Returns boolean

  • Parameters

    Returns boolean

Generated using TypeDoc