HashTable<T>

Guide: /guide/data-structures/hash-table

Generic Types

T - type of collection elements

Implements interfaces

IKeyValueStorage

Methods

constructor(initialCapacity?: number): HashTable<T>

Creates empty instance

Params:
NameTypeRequiredDefaultDescription
initialCapacitynumber-100Initial capacity of table
(0 < capacity < NUMBER.MAX_VALUE)
Throws: ValueOutOfRangeException when given capacity is out of range



set(key: string, value: T): void

Add new element or update its value by key

Params:
NameTypeRequiredDefaultDescription
keystring+--
valueT+--



has(key: string): boolean

Check if hash table has given element by key

Params:
NameTypeRequiredDefaultDescription
keystring+--



get(key: string): T

Get element by its key

Params:
NameTypeRequiredDefaultDescription
keystring+--
Throws: IsNotFoundException when key to search was not found



delete(key: string): void

Remove element from hashtable by its key

Params:
NameTypeRequiredDefaultDescription
keystring+--
Throws: IsNotFoundException when key to remove was not found



clear(): void

Remove all elements from table



length(): number

Get table size