Class HashMap<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

    Remove the element of the specified key.

    Returns

    Whether erase successfully.

    Parameters

    • key: K

      The key you want to remove.

    • Optional isObject: boolean

      Tell us if the type of inserted key is object to improve efficiency.
      If a undefined value is passed in, the type will be automatically judged.

    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

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

    Returns

    The size of container after setting.

    Parameters

    • key: K

      The key want to insert.

    • value: V

      The value want to set.

    • Optional isObject: boolean

      Tell us if the type of inserted key is object to improve efficiency.
      If a undefined value is passed in, the type will be automatically judged.

    Returns number

  • Description

    Get the value of the element of the specified key.

    Example

    const val = container.getElementByKey(1);
    

    Parameters

    • key: K

      The key want to search.

    • Optional isObject: boolean

      Tell us if the type of inserted key is object to improve efficiency.
      If a undefined value is passed in, the type will be automatically judged.

    Returns undefined | V

  • Description

    Check key if exist in container.

    Returns

    An iterator pointing to the element if found, or super end if not found.

    Parameters

    • key: K

      The element you want to search.

    • Optional isObject: boolean

      Tell us if the type of inserted key is object to improve efficiency.
      If a undefined value is passed in, the type will be automatically judged.

    Returns HashMapIterator<K, V>

  • Description

    Iterate over all elements in the container.

    Example

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

    Parameters

    • callback: ((element: [K, V], index: number, hashMap: HashMap<K, V>) => void)

      Callback function like Array.forEach.

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

          • element: [K, V]
          • index: number
          • hashMap: HashMap<K, V>

          Returns void

    Returns void

Properties

HASH_TAG: symbol = ...

Description

Unique symbol used to tag object.

Constructors

Generated using TypeDoc