Class OrderedSet<K>

Type Parameters

  • K

Hierarchy

Accessors

  • get length(): number
  • Returns

    The size of the container.

    Example

    const container = new Vector([1, 2]);
    console.log(container.length); // 2

    Returns number

Methods

  • Description

    Update node's key by iterator.

    Returns

    Whether the modification is successful.

    Example

    const st = new orderedSet([1, 2, 5]);
    const iter = st.find(2);
    st.updateKeyByIterator(iter, 3); // then st will become [1, 3, 5]

    Parameters

    • iter: TreeIterator<K, undefined>

      The iterator you want to change.

    • key: K

      The key you want to update.

    Returns boolean

  • Description

    Removes the element at the specified position.

    Returns

    The container length after erasing.

    Example

    container.eraseElementByPos(-1); // throw a RangeError
    

    Parameters

    • pos: number

      The element's position you want to remove.

    Returns number

  • Description

    Iterate over all elements in the container.

    Example

    container.forEach((element, index) => console.log(element, index));
    

    Parameters

    • callback: ((element: K, index: number, set: OrderedSet<K>) => void)

      Callback function like Array.forEach.

        • (element: K, index: number, set: OrderedSet<K>): void
        • Parameters

          Returns void

    Returns void

  • Description

    Insert element to set.

    Returns

    The size of container after setting.

    Example

    const st = new OrderedSet([2, 4, 5]);
    const iter = st.begin();
    st.insert(1);
    st.insert(3, iter); // give a hint will be faster.

    Parameters

    • key: K

      The key want to insert.

    • Optional hint: OrderedSetIterator<K>

      You can give an iterator hint to improve insertion efficiency.

    Returns number

Properties

enableIndex: boolean

Constructors

  • Example

    new OrderedSet();
    new OrderedSet([0, 1, 2]);
    new OrderedSet([0, 1, 2], (x, y) => x - y);
    new OrderedSet([0, 1, 2], (x, y) => x - y, true);

    Type Parameters

    • K

    Parameters

    • container: initContainer<K> = []

      The initialization container.

    • Optional cmp: ((x: K, y: K) => number)

      The compare function.

        • (x: K, y: K): number
        • Parameters

          • x: K
          • y: K

          Returns number

    • Optional enableIndex: boolean

      Whether to enable iterator indexing function.

    Returns OrderedSet<K>

Generated using TypeDoc