0.2.4 • Published 4 years ago

@yiminghe/rbtree v0.2.4

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

@yiminghe/rbtree


red-black tree

NPM version build status Test coverage node version npm download

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

0.2.4

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.1

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.0

4 years ago