1.0.5 • Published 4 years ago

ts-data-structures v1.0.5

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

ts-data-structures

Build Status Coverage Status npm version

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