Dictionary constructor
initial data as array of tuples - [key, value]
initial Dictionary size or DictionaryOptions object
Current hash function
Number elements in dictionary
Dictionary capacity, before resizing
Dictionary iterator for iteration across all key-value tuples
Complexity: O(n)
Clear all values in Dictionary
Complexity: O(n)
Get value from Dictionary by key
Complexity: O(1) / O(n)
Check if Dictionary has a key
Complexity: O(1) / O(n)
Check if Dictionary has a value
Complexity: O(n)
Dictionary iterator for iteration across all keys
Complexity: O(n)
Remove value from Dictionary by key
true
if key-value was really deleted, false
if no key available
Complexity: O(1) / O(n)
Resize dictionary for most efficient data access Called automatically, if length equal size, before insert new key-value pair Increased size 25% of prev value, 100% or 50% for size less then 32
Complexity: O(n)
Set / update value in Dictionary by key
Complexity: O(1) / O(n)
Dictionary iterator for iteration across all values
Complexity: O(n)
Dictionary (hash table)
In computing, a hash table (hash map) is a data structure that implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index, also called a hash code, into an array of buckets or slots, from which the desired value can be found. Ideally, the hash function will assign each key to a unique bucket, but most hash table designs employ an imperfect hash function, which might cause hash collisions where the hash function generates the same index for more than one key. Such collisions are always accommodated in some way.
source: tutorialspoint.com
Complexity
O(1)
O(n)
O(1)
O(n)
O(n)
O(n)
O(1)
O(n)
O(1)
O(n)
O(n)
O(n)
Reference
import { Dictionary } from '@pencroff/ts-algorithms/dist/structure/dictionary'; const q = new Dictionary([1, 2, 3])
Dictionary used LinkedList for buckets and murmur2_32 as hashing function (selected as most randomness - link).
At the moment Dictionary keys expected to be
string
Note:
Native JS object is kind of Dictionary