Nefariously Programmed Mecha
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

sangja

0.1.1 • Public • Published

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

Methods Optional Stack Queue LinkedList
Implemented O O O O
Constructor new 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)
Read get(), 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) O O O O
map(f) O O O O
flatMap(f) O O O O
filter(f) O O O O
size() O O O O
isEmpty() O O O O
reversed() - O O O
some(f) O O O O
every(f) O O O O
includes(v) O O O O
[Symbol.iterator] O O O O

Tree Data Structures

Methods Heap BinarySearchTree
Implemented O O
Constructor new Heap([iterable][,options]) new BinarySearchTree([iterable][,options])
Add add(item) add(item)
Add All addAll(iterable) addAll(iterable)
Read peek() peek()
Update - -
Delete pop() pop()
Delete with value - remove(v)
Delete with predicate - removeMatch(f)
Delete All clear() clear()
find(f) O O
findOptional(f) - -
forEach(f) O O
map(f[,options]) O O
flatMap(f[,options]) O O
filter(f[,options]) O O
size() O O
isEmpty() O O
reversed() O O
some(f) O O
every(f) O O
includes(v) O O
[Symbol.iterator] O O
inorder([f]) - O
preorder([f]) - O
postorder([f]) - O
breadthFirst([f]) O O

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

Install

npm i sangja

DownloadsWeekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

338 kB

Total Files

26

Last publish

Collaborators

  • avatar