1.0.0 • Published 4 years ago

@styiannis/data-structures v1.0.0

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

@styiannis/data-structures

Build Status Coverage Status Libraries.io depndency status for GitHub repoMaintainability GitHub package.json version (branch) GitHub tag (latest by date) npm (scoped) GitHub

Javascript implementation of classic and advanced data structures.

Table of contents

Installation

Install via NPM:

$ npm install @styiannis/data-structures

Usage

Print data structures list

const ds = require('@styiannis/data-structures');

console.log( ds );

// Output:

{
  'BTree': [Function: BTree],
  'BinarySearchTree': [Function: BinarySearchTree],
  'LeftThreadedBinarySearchTree': [Function: LeftThreadedBinarySearchTree],
  'RedBlackTree': [Function: RedBlackTree],
  'RightThreadedBinarySearchTree': [Function: RightThreadedBinarySearchTree],
  'ThreadedBinarySearchTree': [Function: ThreadedBinarySearchTree]
}

Basic data structure usage

const { RedBlackTree } = require('@styiannis/data-structures');

// Create a Red-black tree
const rbt = RedBlackTree();

// Insert items into the tree
rbt.set( 46, 'foo' );
rbt.set( 13, 'baz' );
rbt.set( 75, 'bar' );

// Get tree item value specified by key
console.log( rbt.get( 13 ) );  // Output: 'baz'

// Check for key within the tree
console.log( rbt.has( 46 ) );  // Output: true

// Remove item from tree
console.log( rbt.delete( 75 ) );  // Output: true

Documentation

B trees

Binary search trees

License

This project is licensed under the MIT License