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-based
API
Sequence
Random access sequence, supports length
, push
, get
and set
init
Create a new Sequence
;let seq = ;
length
Get the length of a sequence
let len = sequencelength;
push(val)
Push a new element of any type into sequence
sequence;sequence;
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 the first elementsequence; // get the last elementsequence; // throws an error if `index` is out of range
set(index, val)
Set element at index
. Similar rules with index
work like get
here.
sequence; // set the first elementsequence; // set the last elementsequence; // throws an error if `index` is out of range
PriorityQueue
PriorityQueue, supports push
and pop
.
init
Create a new priority queue.
;let queue = ;
empty
Check if the queue is empty.
let empty = queueempty; // true or false
push(element, prioriry)
Push an element of any type with priority
. priority
should be a non-negative integer or an error will be throwed.
queue;queue;queue; // throws an error if `priority` is negative
pop()
Pop the element with largest priority. Throws an error if queue is already empty.
let element = queue;