fingertree-based v1.0.3
fingertree-based-js
Applications of Finger Tree. This project also demostrates usage of Finger Tree in implementing other data structures.
Setup
Using npm:
npm install fingertree-basedAPI
Sequence
Random access sequence, supports length, push, get and set
init
Create a new Sequence
import { Sequence } from 'fingertree-based';
let seq = new Sequence;length
Get the length of a sequence
let len = sequence.length;push(val)
Push a new element of any type into sequence
sequence.push('a');
sequence.push(1);get(index)
Get element positioned by index, zero-indexed. Minus value is also allowed. It will throw an error if index out of range.
sequence.get(0); // get the first element
sequence.get(-1); // get the last element
sequence.get(1000000); // throws an error if `index` is out of rangeset(index, val)
Set element at index. Similar rules with index work like get here.
sequence.set(0, 'hello'); // set the first element
sequence.set(-1, 1); // set the last element
sequence.set(10000, 'error'); // throws an error if `index` is out of rangePriorityQueue
PriorityQueue, supports push and pop.
init
Create a new priority queue.
import { PriorityQueue } from 'fingertree-based';
let queue = new PriorityQueue;empty
Check if the queue is empty.
let empty = queue.empty; // true or falsepush(element, prioriry)
Push an element of any type with priority. priority should be a non-negative integer or an error will be throwed.
queue.push('a', 1);
queue.push(123, 0);
queue.push('error', -1); // throws an error if `priority` is negativepop()
Pop the element with largest priority. Throws an error if queue is already empty.
let element = queue.pop();