Skip to content

Javascript implementation of classic and advanced data structures

License

Notifications You must be signed in to change notification settings

styiannis/data-structures-js

Repository files navigation

@styiannis/data-structures

Build Status Coverage Status Known Vulnerabilities Maintainability 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