@yiminghe/rbtree
v0.2.4
Published
red-black-tree
Downloads
3
Readme
@yiminghe/rbtree
red-black tree
usage
import RBTree from '@yiminghe/rbtree';
const tree = new RBTree();
tree.insert(10,'a');
tree.insert(11,'b');
tree.delete(10);
console.log(tree.find(10)) // => undefined
console.log(tree.find(11)) // => 'b'
API
class RBTree
methods
constructor(sorter:(aKey, bKey)=>number, merger:(aVal,bVal)=>any)
sort function: aKey>bKey:>0, aKey==bKey:0, aKey<bKey:<0, sorter defaults to: (a,b)=>a-b;
merger function: how to merge val when key is the same, defaults to override with new val
insert(key:any,value:any)
delete(key:any)
has(key:any):boolean
check whether tree has key node
find(key:any)
find value associated with this key
lowerBound(key:any)
find val by lower bound
upperBound(key:any)
find val by upper bound