@skapoor8/mjolnir
v0.5.0
Published
A data structures and algorithms library
Downloads
2
Readme
Mjolnir
A data structures and algorithms library.
Package Contents
Data Structures
- Queue
- Stack
- Heap
- SLL (singly linked list)
Algorithms
- search
- binarySearch()
- sort
- quickSort()
- bubbleSort()
- insertionSort()
- mergeSort()
- HeapSort()
Usage
To install
npm i @skapoor8/mjolnir
Example:
// testStack.js
const {Stack} = require('@skapoor8/mjolnir');
var s = new Stack();
s.push(1);
s.push(2);
s.push(3);
s.pop();
console.log(s.toString());
Run with bash node testStack.js
Output:
[1,2]
API
Data Structures
Stack
- new Stack()
- Stack.push(item)
- Stack.pop()
- Stack.isEmpty()
- Stack.toString()
Queue
- new Queue()
- Queue.enqueue(item)
- Queue.dequeue()
- Queue.isEmpty()
Heap
- new Heap(compare, order)
Singly Linked List (SLL)
- new SLL()
- SLL.push(item)
- SLL.pop()
- SLL.shift(item)
- SLL.unshift()
- SLL.reverse()
- SLL.at(index)
- SLL.put(index, item)
- SLL.map(f)
- SLL.toString()
- SLL.fromArray()
Algorithms
Search
- binarySearch(Array/SLL, searchFunc)
Sort
- quickSort()
- bubbleSort()
- insertionSort()
- mergeSort()
- heapSort()
Philosophy
- Well defined interfaces that enforce invariants
- Idiomatic and interchangable interfaces - SLL should be interchangable with JS arrays throughout this lib
Questions
- Idiomatic error handling?
- Printing to console?
- Idiomatic interfaces?
- Handling large data sets?
Pending Improvements
- Add iterators where appropriate
- Typescript bindings
- Add jsDocs
- Add other data structures: set, trees, graphs, dll and cll
- Add unit tests for data structures
- Needs es6 wrapper for browser environments, possibly some polyfills