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:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| initialCapacity | number | - | 100 | Initial 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:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| key | string | + | - | - |
| value | T | + | - | - |
has(key: string): boolean
Check if hash table has given element by key
Params:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| key | string | + | - | - |
get(key: string): T
Get element by its key
Params:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| key | string | + | - | - |
Throws: IsNotFoundException when key to search was not found
delete(key: string): void
Remove element from hashtable by its key
Params:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| key | string | + | - | - |
Throws: IsNotFoundException when key to remove was not found
clear(): void
Remove all elements from table
length(): number
Get table size