@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.
Files changed (65) hide show
  1. package/.babelrc +8 -0
  2. package/.travis.yml +14 -0
  3. package/LICENSE +21 -0
  4. package/README.md +172 -0
  5. package/dist/main.cjs.js +799 -0
  6. package/dist/main.esm.js +794 -0
  7. package/dist/main.umd.js +805 -0
  8. package/docs/Interval.html +1609 -0
  9. package/docs/IntervalTree.html +1506 -0
  10. package/docs/classes_interval.js.html +173 -0
  11. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  12. package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
  13. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  14. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  15. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  16. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  17. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  18. package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
  19. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  20. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  21. package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
  22. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  23. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  24. package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  25. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  26. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  27. package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
  28. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  29. package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
  30. package/docs/fonts/OpenSans-Semibold-webfont.svg +1830 -0
  31. package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  32. package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
  33. package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  34. package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +1830 -0
  35. package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  36. package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  37. package/docs/index.html +197 -0
  38. package/docs/index.js.html +624 -0
  39. package/docs/interval.js.html +184 -0
  40. package/docs/intervalTree.js.html +624 -0
  41. package/docs/scripts/linenumber.js +25 -0
  42. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  43. package/docs/scripts/prettify/lang-css.js +2 -0
  44. package/docs/scripts/prettify/prettify.js +28 -0
  45. package/docs/styles/jsdoc-default.css +692 -0
  46. package/docs/styles/prettify-jsdoc.css +111 -0
  47. package/docs/styles/prettify-tomorrow.css +132 -0
  48. package/examples/browser/index.html +49 -0
  49. package/examples/create-react-app/package.json +15 -0
  50. package/examples/create-react-app/public/index.html +11 -0
  51. package/examples/create-react-app/src/App.js +38 -0
  52. package/examples/create-react-app/src/ComposersList.js +15 -0
  53. package/examples/create-react-app/src/index.js +5 -0
  54. package/examples/es6-module/index.html +50 -0
  55. package/examples/nodejs/index.js +23 -0
  56. package/index.d.ts +65 -0
  57. package/index.js +6 -0
  58. package/package.json +52 -0
  59. package/rollup.config.js +21 -0
  60. package/src/classes/interval.js +131 -0
  61. package/src/classes/intervalTree.js +564 -0
  62. package/src/classes/node.js +97 -0
  63. package/src/utils/constants.js +16 -0
  64. package/test/intervalTree.js +232 -0
  65. package/test/node.js +64 -0
package/.babelrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "presets": ["@babel/preset-env"],
3
+ "env": {
4
+ "test": {
5
+ "plugins": [ "istanbul" ]
6
+ }
7
+ }
8
+ }
package/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: node_js
2
+
3
+ node_js:
4
+ - stable
5
+
6
+ install:
7
+ - npm install
8
+
9
+ script:
10
+ - npm run test
11
+
12
+ # Send coverage data to Coveralls
13
+ after_success: npm run coverage
14
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 alexbol99
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # Fork
2
+ This fork support strings as keys.
3
+
4
+ # Interval Tree
5
+
6
+ The package **@flatten-js/interval-tree** 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).
7
+ Cormen shows that insertion, deletion of nodes and range queries take *O(log(n))* time where n is the number of items
8
+ stored in the tree.
9
+
10
+ This package is a part of [flatten-js](https://github.com/alexbol99/flatten-js) library.
11
+
12
+ Package [flatten-interval-tree](https://www.npmjs.com/package/flatten-interval-tree) is not supported and will be deprecated soon.
13
+
14
+ ## Contacts
15
+
16
+ Follow me on Twitter [@alex_bol_](https://twitter.com/alex_bol_)
17
+
18
+ ## Installation
19
+ ```bash
20
+ npm install --save @flatten-js/interval-tree
21
+ ```
22
+ ## Usage
23
+ ```javascript
24
+ import IntervalTree from '@flatten-js/interval-tree'
25
+ ```
26
+
27
+ ### What is interval
28
+ Tree stores pairs <key, value> where key is an interval, and value is any value<br/>
29
+ Interval is a pair of numbers or a pair of any comparable objects on which may be defined predicates
30
+ *equal*, *less* and method *max(p1, p2)* that returns maximum in a pair.
31
+
32
+ When interval is an object rather than pair of numbers, this object should have properties *low*, *high*, *max*
33
+ and implement methods *less_than(), equal_to(), intersect(), not_intersect(), clone(), output()*.
34
+ Two static methods *comparable_max(), comparable_less_than()* define how to compare values in pair. <br/>
35
+ This interface is described in typescript definition file *index.d.ts*
36
+
37
+ Axis aligned rectangle is an example of such interval.
38
+ We may look at rectangle as an interval between its low left and top right corners.
39
+ See **Box** class in [flatten-js](https://github.com/alexbol99/flatten-js) library as the example
40
+ of Interval interface implementation
41
+
42
+ ### Example
43
+
44
+ ```javascript
45
+ let tree = new IntervalTree();
46
+
47
+ let intervals = [[6,8],[1,4],[5,12],[1,1],[5,7]];
48
+
49
+ // Insert interval as a key and string "val0", "val1" etc. as a value
50
+ for (let i=0; i < intervals.length; i++) {
51
+ tree.insert(intervals[i],"val"+i);
52
+ }
53
+
54
+ // Get array of keys sorted in ascendant order
55
+ let sorted_intervals = tree.keys; // expected array [[1,1],[1,4],[5,7],[5,12],[6,8]]
56
+
57
+ // Search items which keys intersect with given interval, and return array of values
58
+ let values_in_range = tree.search([2,3]); // expected array ['val1']
59
+ ```
60
+
61
+ ### Constructor
62
+ Create new instance of interval tree
63
+ ```javascript
64
+ let tree = new IntervalTree()
65
+ ```
66
+
67
+ ### Insert(key[, value])
68
+ Insert new item into the tree. Key is an interval object or pair of numbers [low, high]. <br/>
69
+ Value may represent any value or reference to any object. If value omitted, tree will store and retrieve keys as values. <br/>
70
+ Method returns reference to the inserted node
71
+ ```javascript
72
+ let node = tree.insert(key, value)
73
+ ```
74
+
75
+ ### Exist(key,value)
76
+ Method returns true if item {key, value} exists in the tree. <br/>
77
+ Method may be useful if need to support unique items.
78
+ ```javascript
79
+ let exist = tree.exist(key, value)
80
+ ```
81
+
82
+ ### Remove(key, value)
83
+ Removes item from the tree. Returns true if item was actually deleted, false if not found
84
+ ```javascript
85
+ let removed = tree.remove(key, value)
86
+ ```
87
+
88
+ ### Search(interval[, outputMapperFn])
89
+ Returns array of values which keys intersected with given interval. <br/>
90
+ ```javascript
91
+ let resp = tree.search(interval)
92
+ ```
93
+ Optional *outputMapperFn(value, key)* enables to map search results into custom defined output.
94
+ Example:
95
+ ```javascript
96
+ const composers = [
97
+ {name: "Ludwig van Beethoven", period: [1770, 1827]},
98
+ {name: "Johann Sebastian Bach", period: [1685, 1750]},
99
+ {name: "Wolfgang Amadeus Mozart", period: [1756, 1791]},
100
+ {name: "Johannes Brahms", period: [1833, 1897]},
101
+ {name: "Richard Wagner", period: [1813, 1883]},
102
+ {name: "Claude Debussy", period: [1862, 1918]},
103
+ {name: "Pyotr Ilyich Tchaikovsky", period: [1840, 1893]},
104
+ {name: "Frédéric Chopin", period: [1810, 1849]},
105
+ {name: "Joseph Haydn", period: [1732, 1809]},
106
+ {name: "Antonio Vivaldi", period: [1678, 1741]}
107
+ ];
108
+ const tree = new IntervalTree();
109
+ for (let composer of composers)
110
+ tree.insert(composer.period, composer.name);
111
+
112
+ // Great composers who lived in 17th century
113
+ const searchRes = tree.search( [1600,1700],
114
+ (name, period) => {return `${name} (${period.low}-${period.high})`});
115
+
116
+ console.log(searchRes)
117
+
118
+ // expected to be
119
+ // [ 'Antonio Vivaldi (1678-1741)', 'Johann Sebastian Bach (1685-1750)' ]
120
+ ```
121
+
122
+
123
+ ### Size
124
+ Returns number of items stored in the tree (getter)
125
+ ```javascript
126
+ let size = tree.size
127
+ ```
128
+
129
+ ### Keys
130
+ Returns tree keys in ascendant order (getter)
131
+ ```javascript
132
+ let keys = tree.keys
133
+ ```
134
+
135
+ ### Values
136
+ Returns tree values in ascendant keys order (getter)
137
+ ```javascript
138
+ let values = tree.values
139
+ ```
140
+
141
+ ### Items
142
+ Returns items in ascendant keys order (getter)
143
+ ```javascript
144
+ let items = tree.items
145
+ ```
146
+
147
+ ### ForEach(visitor)
148
+ Enables to traverse the whole tree and perform operation for each item
149
+ ```javascript
150
+ tree.forEach( (key, value) => console.log(value) )
151
+ ```
152
+
153
+ ### Map(callback)
154
+ Creates new tree with same keys using callback to transform (key,value) to a new value
155
+ ```javascript
156
+ let tree1 = tree.map((value, key) => (key.high-key.low))
157
+ ```
158
+
159
+ ## Documentation
160
+ Documentation may be found here: [https://alexbol99.github.io/flatten-interval-tree](https://alexbol99.github.io/flatten-interval-tree/)
161
+
162
+ ## Tests
163
+ ```bash
164
+ npm test
165
+ ```
166
+ ## Contributors
167
+
168
+ 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.
169
+
170
+ ## License
171
+
172
+ MIT