@live-change/flatten-interval-tree 0.8.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +8 -0
- package/.travis.yml +14 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/main.cjs.js +799 -0
- package/dist/main.esm.js +794 -0
- package/dist/main.umd.js +805 -0
- package/docs/Interval.html +1609 -0
- package/docs/IntervalTree.html +1506 -0
- package/docs/classes_interval.js.html +173 -0
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/docs/index.html +197 -0
- package/docs/index.js.html +624 -0
- package/docs/interval.js.html +184 -0
- package/docs/intervalTree.js.html +624 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/styles/jsdoc-default.css +692 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/examples/browser/index.html +49 -0
- package/examples/create-react-app/package.json +15 -0
- package/examples/create-react-app/public/index.html +11 -0
- package/examples/create-react-app/src/App.js +38 -0
- package/examples/create-react-app/src/ComposersList.js +15 -0
- package/examples/create-react-app/src/index.js +5 -0
- package/examples/es6-module/index.html +50 -0
- package/examples/nodejs/index.js +23 -0
- package/index.d.ts +65 -0
- package/index.js +6 -0
- package/package.json +52 -0
- package/rollup.config.js +21 -0
- package/src/classes/interval.js +131 -0
- package/src/classes/intervalTree.js +564 -0
- package/src/classes/node.js +97 -0
- package/src/utils/constants.js +16 -0
- package/test/intervalTree.js +232 -0
- package/test/node.js +64 -0
|
Binary file
|
|
Binary file
|
package/docs/index.html
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>Home - Documentation</title>
|
|
7
|
+
|
|
8
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
9
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
10
|
+
<!--[if lt IE 9]>
|
|
11
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
12
|
+
<![endif]-->
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
|
|
19
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
20
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
21
|
+
<div class="navicon"></div>
|
|
22
|
+
</label>
|
|
23
|
+
|
|
24
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
25
|
+
|
|
26
|
+
<nav>
|
|
27
|
+
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Interval.html">Interval</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#.comparable_less_than">comparable_less_than</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#.comparable_max">comparable_max</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#clone">clone</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#equal_to">equal_to</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#intersect">intersect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#less_than">less_than</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#merge">merge</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#not_intersect">not_intersect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Interval.html#output">output</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="IntervalTree.html">IntervalTree</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="IntervalTree.html#exist">exist</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="IntervalTree.html#forEach">forEach</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="IntervalTree.html#insert">insert</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="IntervalTree.html#isEmpty">isEmpty</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="IntervalTree.html#map">map</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="IntervalTree.html#remove">remove</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="IntervalTree.html#search">search</a></span></li>
|
|
28
|
+
</nav>
|
|
29
|
+
|
|
30
|
+
<div id="main">
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
<section class="readme">
|
|
51
|
+
<article><h1>Interval Tree</h1>
|
|
52
|
+
<p><a href="https://badge.fury.io/js/%40flatten-js%2Finterval-tree"><img src="https://badge.fury.io/js/%40flatten-js%2Finterval-tree.svg" alt="npm version"></a>
|
|
53
|
+
<a href="https://travis-ci.org/alexbol99/flatten-interval-tree"><img src="https://travis-ci.org/alexbol99/flatten-interval-tree.svg?branch=master" alt="Build Status"></a>
|
|
54
|
+
<a href="https://coveralls.io/github/alexbol99/flatten-interval-tree?branch=master"><img src="https://coveralls.io/repos/github/alexbol99/flatten-interval-tree/badge.svg?branch=master" alt="Coverage Status"></a></p>
|
|
55
|
+
<p>The package <strong>@flatten-js/interval-tree</strong> is an implementation of interval binary search tree according to Cormen et al. Introduction to Algorithms (2009, Section 14.3: Interval trees, pp. 348–354).
|
|
56
|
+
Cormen shows that insertion, deletion of nodes and range queries take <em>O(log(n))</em> time where n is the number of items
|
|
57
|
+
stored in the tree.</p>
|
|
58
|
+
<p>This package is a part of <a href="https://github.com/alexbol99/flatten-js">flatten-js</a> library.</p>
|
|
59
|
+
<p>Package <a href="https://www.npmjs.com/package/flatten-interval-tree">flatten-interval-tree</a> is not supported and will be deprecated soon.</p>
|
|
60
|
+
<h2>Contacts</h2>
|
|
61
|
+
<p>Follow me on Twitter <a href="https://twitter.com/alex_bol_">@alex_bol_</a></p>
|
|
62
|
+
<h2>Installation</h2>
|
|
63
|
+
<pre class="prettyprint source lang-bash"><code>npm install --save @flatten-js/interval-tree
|
|
64
|
+
</code></pre>
|
|
65
|
+
<h2>Usage</h2>
|
|
66
|
+
<pre class="prettyprint source lang-javascript"><code>import IntervalTree from '@flatten-js/interval-tree'
|
|
67
|
+
</code></pre>
|
|
68
|
+
<h3>What is interval</h3>
|
|
69
|
+
<p>Tree stores pairs <key, value> where key is an interval, and value is any value<br/>
|
|
70
|
+
Interval is a pair of numbers or a pair of any comparable objects on which may be defined predicates
|
|
71
|
+
<em>equal</em>, <em>less</em> and method <em>max(p1, p2)</em> that returns maximum in a pair.</p>
|
|
72
|
+
<p>When interval is an object rather than pair of numbers, this object should have properties <em>low</em>, <em>high</em>, <em>max</em>
|
|
73
|
+
and implement methods <em>less_than(), equal_to(), intersect(), not_intersect(), clone(), output()</em>.
|
|
74
|
+
Two static methods <em>comparable_max(), comparable_less_than()</em> define how to compare values in pair. <br/>
|
|
75
|
+
This interface is described in typescript definition file <em>index.d.ts</em></p>
|
|
76
|
+
<p>Axis aligned rectangle is an example of such interval.
|
|
77
|
+
We may look at rectangle as an interval between its low left and top right corners.
|
|
78
|
+
See <strong>Box</strong> class in <a href="https://github.com/alexbol99/flatten-js">flatten-js</a> library as the example
|
|
79
|
+
of Interval interface implementation</p>
|
|
80
|
+
<h3>Example</h3>
|
|
81
|
+
<pre class="prettyprint source lang-javascript"><code>let tree = new IntervalTree();
|
|
82
|
+
|
|
83
|
+
let intervals = [[6,8],[1,4],[5,12],[1,1],[5,7]];
|
|
84
|
+
|
|
85
|
+
// Insert interval as a key and string "val0", "val1" etc. as a value
|
|
86
|
+
for (let i=0; i < intervals.length; i++) {
|
|
87
|
+
tree.insert(intervals[i],"val"+i);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Get array of keys sorted in ascendant order
|
|
91
|
+
let sorted_intervals = tree.keys; // expected array [[1,1],[1,4],[5,7],[5,12],[6,8]]
|
|
92
|
+
|
|
93
|
+
// Search items which keys intersect with given interval, and return array of values
|
|
94
|
+
let values_in_range = tree.search([2,3]); // expected array ['val1']
|
|
95
|
+
</code></pre>
|
|
96
|
+
<h3>Constructor</h3>
|
|
97
|
+
<p>Create new instance of interval tree</p>
|
|
98
|
+
<pre class="prettyprint source lang-javascript"><code>let tree = new IntervalTree()
|
|
99
|
+
</code></pre>
|
|
100
|
+
<h3>Insert(key[, value])</h3>
|
|
101
|
+
<p>Insert new item into the tree. Key is an interval object or pair of numbers [low, high]. <br/>
|
|
102
|
+
Value may represent any value or reference to any object. If value omitted, tree will store and retrieve keys as values. <br/>
|
|
103
|
+
Method returns reference to the inserted node</p>
|
|
104
|
+
<pre class="prettyprint source lang-javascript"><code>let node = tree.insert(key, value)
|
|
105
|
+
</code></pre>
|
|
106
|
+
<h3>Exist(key,value)</h3>
|
|
107
|
+
<p>Method returns true if item {key, value} exists in the tree. <br/>
|
|
108
|
+
Method may be useful if need to support unique items.</p>
|
|
109
|
+
<pre class="prettyprint source lang-javascript"><code>let exist = tree.exist(key, value)
|
|
110
|
+
</code></pre>
|
|
111
|
+
<h3>Remove(key, value)</h3>
|
|
112
|
+
<p>Removes item from the tree. Returns true if item was actually deleted, false if not found</p>
|
|
113
|
+
<pre class="prettyprint source lang-javascript"><code>let removed = tree.remove(key, value)
|
|
114
|
+
</code></pre>
|
|
115
|
+
<h3>Search(interval[, outputMapperFn])</h3>
|
|
116
|
+
<p>Returns array of values which keys intersected with given interval. <br/></p>
|
|
117
|
+
<pre class="prettyprint source lang-javascript"><code>let resp = tree.search(interval)
|
|
118
|
+
</code></pre>
|
|
119
|
+
<p>Optional <em>outputMapperFn(value, key)</em> enables to map search results into custom defined output.
|
|
120
|
+
Example:</p>
|
|
121
|
+
<pre class="prettyprint source lang-javascript"><code>const composers = [
|
|
122
|
+
{name: "Ludwig van Beethoven", period: [1770, 1827]},
|
|
123
|
+
{name: "Johann Sebastian Bach", period: [1685, 1750]},
|
|
124
|
+
{name: "Wolfgang Amadeus Mozart", period: [1756, 1791]},
|
|
125
|
+
{name: "Johannes Brahms", period: [1833, 1897]},
|
|
126
|
+
{name: "Richard Wagner", period: [1813, 1883]},
|
|
127
|
+
{name: "Claude Debussy", period: [1862, 1918]},
|
|
128
|
+
{name: "Pyotr Ilyich Tchaikovsky", period: [1840, 1893]},
|
|
129
|
+
{name: "Frédéric Chopin", period: [1810, 1849]},
|
|
130
|
+
{name: "Joseph Haydn", period: [1732, 1809]},
|
|
131
|
+
{name: "Antonio Vivaldi", period: [1678, 1741]}
|
|
132
|
+
];
|
|
133
|
+
const tree = new IntervalTree();
|
|
134
|
+
for (let composer of composers)
|
|
135
|
+
tree.insert(composer.period, composer.name);
|
|
136
|
+
|
|
137
|
+
// Great composers who lived in 17th century
|
|
138
|
+
const searchRes = tree.search( [1600,1700],
|
|
139
|
+
(name, period) => {return `${name} (${period.low}-${period.high})`});
|
|
140
|
+
|
|
141
|
+
console.log(searchRes)
|
|
142
|
+
|
|
143
|
+
// expected to be
|
|
144
|
+
// [ 'Antonio Vivaldi (1678-1741)', 'Johann Sebastian Bach (1685-1750)' ]
|
|
145
|
+
</code></pre>
|
|
146
|
+
<h3>Size</h3>
|
|
147
|
+
<p>Returns number of items stored in the tree (getter)</p>
|
|
148
|
+
<pre class="prettyprint source lang-javascript"><code>let size = tree.size
|
|
149
|
+
</code></pre>
|
|
150
|
+
<h3>Keys</h3>
|
|
151
|
+
<p>Returns tree keys in ascendant order (getter)</p>
|
|
152
|
+
<pre class="prettyprint source lang-javascript"><code>let keys = tree.keys
|
|
153
|
+
</code></pre>
|
|
154
|
+
<h3>Values</h3>
|
|
155
|
+
<p>Returns tree values in ascendant keys order (getter)</p>
|
|
156
|
+
<pre class="prettyprint source lang-javascript"><code>let values = tree.values
|
|
157
|
+
</code></pre>
|
|
158
|
+
<h3>Items</h3>
|
|
159
|
+
<p>Returns items in ascendant keys order (getter)</p>
|
|
160
|
+
<pre class="prettyprint source lang-javascript"><code>let items = tree.items
|
|
161
|
+
</code></pre>
|
|
162
|
+
<h3>ForEach(visitor)</h3>
|
|
163
|
+
<p>Enables to traverse the whole tree and perform operation for each item</p>
|
|
164
|
+
<pre class="prettyprint source lang-javascript"><code>tree.forEach( (key, value) => console.log(value) )
|
|
165
|
+
</code></pre>
|
|
166
|
+
<h3>Map(callback)</h3>
|
|
167
|
+
<p>Creates new tree with same keys using callback to transform (key,value) to a new value</p>
|
|
168
|
+
<pre class="prettyprint source lang-javascript"><code>let tree1 = tree.map((value, key) => (key.high-key.low))
|
|
169
|
+
</code></pre>
|
|
170
|
+
<h2>Documentation</h2>
|
|
171
|
+
<p>Documentation may be found here: <a href="https://alexbol99.github.io/flatten-interval-tree/">https://alexbol99.github.io/flatten-interval-tree</a></p>
|
|
172
|
+
<h2>Tests</h2>
|
|
173
|
+
<pre class="prettyprint source lang-bash"><code>npm test
|
|
174
|
+
</code></pre>
|
|
175
|
+
<h2>Contributors</h2>
|
|
176
|
+
<p>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.</p>
|
|
177
|
+
<h2>License</h2>
|
|
178
|
+
<p>MIT</p></article>
|
|
179
|
+
</section>
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
<br class="clear">
|
|
189
|
+
|
|
190
|
+
<footer>
|
|
191
|
+
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> on Thu Jul 04 2019 20:41:00 GMT+0300 (Israel Daylight Time) using the Minami theme.
|
|
192
|
+
</footer>
|
|
193
|
+
|
|
194
|
+
<script>prettyPrint();</script>
|
|
195
|
+
<script src="scripts/linenumber.js"></script>
|
|
196
|
+
</body>
|
|
197
|
+
</html>
|