ts-data-structures
v1.0.5
Published
A collection of common data structures written in TypeScript
Downloads
4
Maintainers
Readme
ts-data-structures
Description:
A collection of common data structures written in TypeScript
Installation:
npm install ts-data-structures
HashTable<Key, Value>
import { HashTable } from 'ts-data-structures'
// create a HashTable that takes keys of type string and values of type number
const table = new HashTable<string, number>();
HashTable.size
table.size // 16
HashTable.entries
table.entries // 0
HashTable.add(key, value)
Add a new key and value pair to the table. The table will be resized if it has too many entries. If a given key already exists, it's value will be updated.
table.add('foo', 42)
table.add('bar', 8)
HashTable.find(key)
Find the value associated with a given key
table.find('foo') // 42
table.find('zap') // undefined
HashTable.resize(size)
Resize the table to a given size
table.resize(32)
table.size // 32