@yiminghe/rbtree
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @yiminghe/rbtree

Weekly Downloads

1

Version

0.2.4

License

MIT

Unpacked Size

92.1 kB

Total Files

11

Last publish

Collaborators

  • yiminghe