0.1.1 • Published 5 years ago

sangja v0.1.1

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

sangja

Sangja is javaScript data structures library.
Implemented data structures provides interfaces similar to array, which is the native data structure of javascript.

Installation

npm install sangja

Implemented Data Structures

Document

https://chacham.github.io/sangja/

Usage

const sangja = require('sangja');

let some = new sangja.Optional(123);
let none = new sangja.Optional();
some.getOrElse(22); // 123
none.getOrElse(22); // 22

let stack = new sangja.Stack();
stack.push(123);
stack.pop(); // 123

let queue = new sangja.Queue();
queue.enqueue(456);
queue.dequeue() // 456

let list = new sangja.LinkedList();
list.addLast(456);
list.addFirst(123);
list.addLast(789);
list.get(0); // 123
list.get(1); // 456
list.getLast() // 789

let heap = new sangja.Heap();
heap.add(123);
heap.pop(); // 123

let bst = new sangja.BinarySearchTree();
bst.addAll([3, 8, 2, 6, 4]);
bst.includes(8); // true
let otherBst = bst.map(v => {value: v}, { key: item => item.value });

Method Summary Table

Linear Data Structures

MethodsOptionalStackQueueLinkedList
ImplementedOOOO
Constructornew Optional([value])new Stack([iterable])new Queue([iterable])new LinkedList([iterable])
Add-push(item)enqueue(item)add([index,]item), addFirst(item), addLast(item)
Add All-pushAll(iterable)enqueueAll(iterable)addAll([index,]iterable), addAllFirst(iterable), addAllLast(iterable)
Readget(), getOrElse(item)top()peek()get(index), getFitst(), getLast()
Update---set(index, value)
Delete with position-pop()dequeue()pop([i]), popFirst(), popLast(), removeAt(i)
Delete with value---remove(v), removeFirst(v), removeLast(v), removeAll(v)
Delete with predicate---removeMatch(f), removeMatchFirst(f), removeMatchLast(f), removeMatchAll(f)
Delete All-clear()clear()clear()-
find(f)---O
findOptional(f)----
forEach(f)OOOO
map(f)OOOO
flatMap(f)OOOO
filter(f)OOOO
size()OOOO
isEmpty()OOOO
reversed()-OOO
some(f)OOOO
every(f)OOOO
includes(v)OOOO
[Symbol.iterator]OOOO

Tree Data Structures

MethodsHeapBinarySearchTree
ImplementedOO
Constructornew Heap([iterable][,options])new BinarySearchTree([iterable][,options])
Addadd(item)add(item)
Add AlladdAll(iterable)addAll(iterable)
Readpeek()peek()
Update--
Deletepop()pop()
Delete with value-remove(v)
Delete with predicate-removeMatch(f)
Delete Allclear()clear()
find(f)OO
findOptional(f)--
forEach(f)OO
map(f[,options])OO
flatMap(f[,options])OO
filter(f[,options])OO
size()OO
isEmpty()OO
reversed()OO
some(f)OO
every(f)OO
includes(v)OO
[Symbol.iterator]OO
inorder([f])-O
preorder([f])-O
postorder([f])-O
breadthFirst([f])OO

Contributing

Sangja is open to any contributions made by the community.
Reporting error, adding test cases, correcting typo, correcting inconsistent comments, fixing awkward sentence, and so on... are all good.

Contact

ccm0702@naver.com

License

Sangja is released under MIT License