Class OrderedMap<K, V>

Type Parameters

  • K

  • V

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, V>

      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, V], index: number, map: OrderedMap<K, V>) => void)

      Callback function like Array.forEach.

        • (element: [K, V], index: number, map: OrderedMap<K, V>): void
        • Parameters

          • element: [K, V]
          • index: number
          • map: OrderedMap<K, V>

          Returns void

    Returns void

  • Description

    Insert a key-value pair or set value by the given key.

    Returns

    The size of container after setting.

    Example

    const mp = new OrderedMap([[2, 0], [4, 0], [5, 0]]);
    const iter = mp.begin();
    mp.setElement(1, 0);
    mp.setElement(3, 0, iter); // give a hint will be faster.

    Parameters

    • key: K

      The key want to insert.

    • value: V

      The value want to set.

    • Optional hint: OrderedMapIterator<K, V>

      You can give an iterator hint to improve insertion efficiency.

    Returns number

  • Description

    Get the value of the element of the specified key.

    Example

    const val = container.getElementByKey(1);
    

    Parameters

    • key: K

      The specified key you want to get.

    Returns undefined | V

Properties

enableIndex: boolean

Constructors

  • Example

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

    Type Parameters

    • K

    • V

    Parameters

    • container: initContainer<[K, V]> = []

      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 OrderedMap<K, V>

Generated using TypeDoc