Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yiminghe/rbtree
javascript red-black tree
https://github.com/yiminghe/rbtree
Last synced: 9 days ago
JSON representation
javascript red-black tree
- Host: GitHub
- URL: https://github.com/yiminghe/rbtree
- Owner: yiminghe
- License: mit
- Created: 2020-01-17T14:45:49.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-25T06:28:51.000Z (over 4 years ago)
- Last Synced: 2024-10-17T10:28:49.981Z (19 days ago)
- Language: TypeScript
- Homepage:
- Size: 31.3 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @yiminghe/rbtree
---red-black tree
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url][npm-image]: http://img.shields.io/npm/v/@yiminghe/rbtree.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@yiminghe/rbtree
[travis-image]: https://img.shields.io/travis/yiminghe/rbtree.svg?style=flat-square
[travis-url]: https://travis-ci.org/yiminghe/rbtree
[coveralls-image]: https://img.shields.io/coveralls/yiminghe/rbtree.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/yiminghe/rbtree?branch=master
[gemnasium-image]: http://img.shields.io/gemnasium/yiminghe/rbtree.svg?style=flat-square
[gemnasium-url]: https://gemnasium.com/yiminghe/rbtree
[node-image]: https://img.shields.io/badge/node.js-%3E=10.0.0-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/@yiminghe/rbtree.svg?style=flat-square
[download-url]: https://npmjs.org/package/@yiminghe/rbtree## 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, aKeya-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