# flatten-interval-tree

> Interval Tree implementation as augmented binary red-black tree

Latest version **0.2.3** (published 2019-02-24) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install flatten-interval-tree
pnpm add flatten-interval-tree
yarn add flatten-interval-tree
bun add flatten-interval-tree
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2019-02-24 |
| First published | 2017-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 55 |
| Author | “Alex |
| Maintainers | alexbol99 |
| Keywords | interval tree, binary search trees |

## Links

- npm: https://www.npmjs.com/package/flatten-interval-tree
- Repository: https://github.com/alexbol99/flatten-interval-tree
- Homepage: https://github.com/alexbol99/flatten-interval-tree#readme
- Issues: https://github.com/alexbol99/flatten-interval-tree/issues
- npm.io page: https://npm.io/package/flatten-interval-tree

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2019-02-24
- 0.3.6 (beta) — 2019-02-18
- 0.2.2 — 2019-02-18
- 0.3.5 — 2019-02-18
- 0.3.4 — 2019-02-12
- 0.3.3 — 2019-02-02
- 0.3.2 — 2019-02-02
- 0.3.1 — 2019-02-02
- 0.3.0 — 2019-02-02
- 0.2.1 — 2018-08-14
- 0.2.0 — 2018-08-14
- 0.1.7 — 2018-04-08
- 0.1.6 — 2017-10-13
- 0.1.5 — 2017-08-31
- 0.1.4 — 2017-05-13
- … 4 more at https://npm.io/package/flatten-interval-tree/versions

## README

# Interval Tree

[![npm version](https://badge.fury.io/js/flatten-interval-tree.svg)](https://badge.fury.io/js/flatten-interval-tree)
[![Build Status](https://travis-ci.org/alexbol99/flatten-js.svg?branch=master)](https://travis-ci.org/alexbol99/flatten-js)

Interval Tree implementation as it is described in Cormen et al. (2009, Section 14.3: Interval trees, pp. 348–354).

## Important note

#### This package is not supported and will be deprecated soon. Consider moving to the scoped version [@flatten-js/interval-tree](https://www.npmjs.com/package/@flatten-js/interval-tree).

## Contacts

Follow me on Twitter [@alex_bol_](https://twitter.com/alex_bol_)


## Installation

```bash
npm install flatten-interval-tree -save
```

## Usage

```js
let IntervalTree = require('flatten-interval-tree');
```

## API Reference

### Constructor
Create new instance of interval tree
```js
let tree = new IntervalTree();
```
### Insert(key, value)
Insert new item into the tree. Key is and interval object or an array of [low, high] numeric values. <br/>
Value may represent any value or refer to any object. If value omitted, tree will store and retrieve keys only. <br/>
If key is an object, it should expose <i>low</i> and <i>high</i> properties and implement the following methods:
<i>less_than, equal_to, intersect, clone, output, maximal_val, val_less_than</i>. <br/>
Method returns reference to the inserted node
```js
let node = tree.insert(key, value);
```
### Exist(key,value)
Method returns true if entry {key, value} exists in the tree. <br/>
Method may be useful if need to support unique items.
```js
let exist = tree.exist(key,value);
```
### Remove(key, value)
Removes item from the tree. Returns true if item was actually deleted, false if not found
```js
let removed = tree.remove(key, value);
```
### Search(interval)
Returns array of values which keys intersected with given interval. <br/>
If tree stores only keys with no values, search returns array of keys which intersect given interval
```js
let resp = tree.search(interval);
```
### Size (getter)
Returns number of items stored in the tree
```js
let size = tree.size;
```
### ForEach(visitor)
Enables to traverse the whole tree and perform operation for each item
```js
tree.forEach( (key, value) => console.log(value) )
```
## Tests
```bash
npm test
```
## Contributors

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

## License

MIT

---
_Source: https://npm.io/package/flatten-interval-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
