@stackomate/data-structures
v0.0.0-development.11
Published
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Build Status](https://www.travis-ci.com/Stackomate/data-structures.svg?branch=master)](https://www.travis-ci.com/Stackomate/da
Downloads
4
Readme
Data-structures
A collection of useful data-structures for Typescript Development.
Usage
npm i @stackomate/data-structures
- Import desired data-structure into your project. See examples below:
Each data-structure contains a prefix to better differentiate similar methods
Composite Key Map (ckm
prefix)
- Documentation: CompositeKeyMap
A map that allows multiple ordered keys (composite key) to be mapped to some value. Can contain an arbitrary number of keys. Keys are stored as pointers that contain maps to the child keys, in recursive tree structure. Important: Order of iteration is not preserved for the keys
Examples
See live example in Stackblitz: Demo
[root] => 10
[root, 'a'] => 20
[root, 'b', 'c'] => 30 (note that root.b is not a key)
BijectiveMap
- Documentation: BijectiveMap
A stricter type of map that only allows Bijective (one-to-one) relationships.
(Credit: Wikipedia)
- Example: Create a mapping of usernames to their respective IDs (CodeSandbox)
import {BijectiveMap} from '@stackomate/data-structures';
const usernameID = new BijectiveMap<string, number>();
usernameID.set('Kyle', 1);
usernameID.set('Mary', 2);
usernameID.set('John', 1); // Error: 'Value has already been registered for another key.'
BijectiveMap
s allow for inversion:
let idUsername = usernameID.invert(); // 1 => 'Kyle', 2 => 'Mary'