@stackomate/data-structures
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-development.11 • Public • Published

Data-structures

styled with prettier Build Status

A collection of useful data-structures for Typescript Development.

Usage

  1. npm i @stackomate/data-structures
  2. 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)

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

A stricter type of map that only allows Bijective (one-to-one) relationships.

Bijection Mapping Example

(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.' 
  • BijectiveMaps allow for inversion:
let idUsername = usernameID.invert(); // 1 => 'Kyle', 2 => 'Mary'

Readme

Keywords

none

Package Sidebar

Install

npm i @stackomate/data-structures

Weekly Downloads

1

Version

0.0.0-development.11

License

MIT

Unpacked Size

1.8 MB

Total Files

430

Last publish

Collaborators

  • rafaelcalpena