The type of key of a given entry.
The type of value associated with the given key.
Construct a new hash-based dictionary.
const d = new HashDict<number, string>()
Similar to JavaScript's built-in map type, the constructor accepts a list of key-value pairs that will immediately be added to the resulting dictionary.
const d = new HashDict<number, string>([
[1, 'one'],
[2, 'two']
])
The dictionary can be tweaked by providing a [[HashDictOptions]] object, which allows to configure things like the default hashing function and value equality.
const d = new HashDict<number, string>({
hash: num => num,
keysEqual: (a, b) => a === b,
valuesEqual: (a, b) => a === b,
elements: [[1, 'one'], [2, 'two']]
})
Generated using TypeDoc
A simple hash-based dictionary that only allows one item with same key.
Most methods in this collection, given that a proper hashing function is set up, are in
Θ(1 + n/k)
. If you're out of luck, this characteristic can grow toO(n)
.When a new entry is added with a key that is already taken, the dictionary will replace the corresponding entry with the new one.