Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HashMap<K, V>

A drop-in replacement for the default ECMA Map implementation that uses hashes keys based on the string view of an Object.

Unlike the default ECMA Map implementation, this version does not maintain insertion order and does not make any guarantees on iteration order nor does enforce key identity equivalency when attempting to look up a mapping. This allows this implementation to store and compare objects that are equal, but not necessarily the same instance.

The hashing algorithm is based on that of Java's HashMap.

Type parameters

  • K

    the type of the key

  • V

    the type of the value

Hierarchy

  • HashMap

Implements

  • Map<K, V>

Index

Constructors

constructor

  • new HashMap(size?: number, iterable?: Iterable<[K, V]>): HashMap
  • Constructs a new Map.

    Parameters

    • Default value size: number = 32

      the number of buckets to spread entries across

    • Optional iterable: Iterable<[K, V]>

      initial entries to add to the map.

    Returns HashMap

Properties

Readonly [Symbol.toStringTag]

[Symbol.toStringTag]: string = "HashMap"
inheritdoc

Protected _size

_size: number = 0

The current size of this map.

Protected Readonly buckets

buckets: [K, V][][]

The buckets for storing key/value pairs. The outer array is the bucket location, with the inner array being the bucket for the entries.

Accessors

size

  • get size(): number
  • inheritdoc

    Returns number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): IterableIterator<[K, V]>
  • inheritdoc

    Returns IterableIterator<[K, V]>

clear

  • clear(): void
  • inheritdoc

    Returns void

delete

  • delete(key: K): boolean
  • inheritdoc

    Parameters

    • key: K

    Returns boolean

entries

  • entries(): IterableIterator<[K, V]>
  • inheritdoc

    Returns IterableIterator<[K, V]>

forEach

  • forEach(callbackFn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void
  • inheritdoc

    Parameters

    • callbackFn: (value: V, key: K, map: Map<K, V>) => void
        • (value: V, key: K, map: Map<K, V>): void
        • Parameters

          • value: V
          • key: K
          • map: Map<K, V>

          Returns void

    • Optional thisArg: any

    Returns void

get

  • get(key: K): V | undefined
  • inheritdoc

    Parameters

    • key: K

    Returns V | undefined

has

  • has(key: K): boolean
  • Returns a boolean asserting whether a value has been associated to the key in the Map object or not.

    Parameters

    • key: K

      the key of the element to test for presence in the Map object

    Returns boolean

    true if the key is currently associated with a value within the map, otherwise returns false

keys

  • keys(): IterableIterator<K>
  • inheritdoc

    Returns IterableIterator<K>

set

  • set(key: K, value: V): this
  • inheritdoc

    Parameters

    • key: K
    • value: V

    Returns this

values

  • values(): IterableIterator<V>
  • Returns IterableIterator<V>