A Set implementation that provides index-based access.

Similar to an Array that only allows unique elements.

Example

const indexedSet = new IndexedSet();
indexedSet.add(1);
indexedSet.add(3);
indexedSet.add(2);
indexedSet.add(1);

console.log(indexedSet); // 1, 3, 2

indexedSet.set(0, 4);
console.log(indexedSet); // 4, 1, 3, 2

indexedSet.set(3, 1);
console.log(indexedSet); // 4, 3, 1, 2

Type Parameters

Hierarchy

Constructors

Properties

#values: T[]
[toStringTag]: string = "IndexedSet"

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

  • Deletes the element at the given index.

    Mutation

    Example

    Remove value at index 1

    const indexedSet = new IndexedSet([1, 2, 3]);

    indexedSet.deleteAt(1);

    console.log([...indexedSet.values()]); // [1, 3]

    Returns

    true if the IndexedSet was modified, otherwise false

    Parameters

    • index: number

      the index to delete

    • Optional deleteCount: number

    Returns boolean

  • Sets the value at the specified index. If the value already exists, it will be moved to the new index, otherwise it will be inserted at the index.

    Example

    Set value

    const indexedSet = new IndexedSet([1, 2, 3]);

    indexedSet.set(0, 3);

    console.log([...indexedSet.values()]); // [3, 1, 2]

    Parameters

    • index: number

      the index where to set the value

    • value: T

      the value to set

    Returns void

Generated using TypeDoc