Skip to content

Commit 86daa89

Browse files
authored
Merge pull request #52 from alexbol99/51_support_for_bigint
Support for bigint
2 parents 27c7e62 + 46bc17d commit 86daa89

File tree

9 files changed

+303
-293
lines changed

9 files changed

+303
-293
lines changed

README.md

+8-11
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@ import IntervalTree from '@flatten-js/interval-tree'
2828

2929
### Notes
3030
Tree stores pairs ```<key,value>``` where key is an interval, and value is an object of any type.
31-
If value omitted, tree stores only keys.
32-
33-
In a ```<key,value>``` tree none of the ```value``` can be
34-
```undefined```.
31+
If value omitted, tree stores only keys. ```value``` cannot be ```undefined```.
3532

36-
Interval can be simply a pair of numbers or it can be
37-
a user-defined object that implements ```IntervalInterface``` described in
33+
Interval can be a pair of numbers or an object that implements ```IntervalInterface``` described in
3834
typescript declaration file ```index.d.ts```.
3935

4036
Axis aligned rectangle is an example of such interval.
4137
We may look at rectangle as an interval between its low left and top right corners.
42-
See **Box** class in [flatten-js](https://github.com/alexbol99/flatten-js) library as an example
43-
of ```IntervalInterface``` implementation.
38+
It makes possible to use interval tree in spatial queries.
39+
See **Box** class in [flatten-js](https://github.com/alexbol99/flatten-js) library for such
40+
implementation.
4441

4542
### Example
4643

@@ -77,13 +74,13 @@ let node = tree.insert(key, value)
7774

7875
### Exist(key, value)
7976
Method returns true if item {key, value} exists in the tree. <br/>
80-
Method may be useful if need to support unique items.
77+
8178
```javascript
8279
let exist = tree.exist(key, value)
8380
```
8481

8582
### Remove(key, value)
86-
Removes item from the tree. Returns true if item was actually deleted, false if not found
83+
Removes item from the tree. Returns true if item was found and deleted, false if not found
8784
```javascript
8885
let removed = tree.remove(key, value)
8986
```
@@ -123,7 +120,7 @@ console.log(searchRes)
123120
```
124121

125122
### Intersect_any(interval)
126-
Returns true if intersection between given and any interval stored in the tree found
123+
Returns true if intersection found between given interval and any of intervals stored in the tree
127124

128125
```javascript
129126
let found = tree.intersect_any(interval)

dist/main.cjs

+69-69
Large diffs are not rendered by default.

dist/main.mjs

+69-69
Large diffs are not rendered by default.

dist/main.umd.js

+69-69
Large diffs are not rendered by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flatten-js/interval-tree",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Interval search tree",
55
"author": "Alex Bol",
66
"license": "MIT",

src/classes/interval.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Interval is a pair of numbers or a pair of any comparable objects on which may be defined predicates
77
* *equal*, *less* and method *max(p1, p1)* that returns maximum in a pair.
8-
* When interval is an object rather than pair of numbers, this object should have properties *low*, *high*, *max*
8+
* When interval is an object rather than a pair of numbers, this object should have properties *low*, *high*, *max*
99
* and implement methods *less_than(), equal_to(), intersect(), not_intersect(), clone(), output()*.
1010
* Two static methods *comparable_max(), comparable_less_than()* define how to compare values in pair. <br/>
1111
* This interface is described in typescript definition file *index.d.ts*
@@ -51,7 +51,7 @@ const Interval = class Interval {
5151
*/
5252
less_than(other_interval) {
5353
return this.low < other_interval.low ||
54-
this.low == other_interval.low && this.high < other_interval.high;
54+
this.low === other_interval.low && this.high < other_interval.high;
5555
}
5656

5757
/**
@@ -60,7 +60,7 @@ const Interval = class Interval {
6060
* @returns {boolean}
6161
*/
6262
equal_to(other_interval) {
63-
return this.low == other_interval.low && this.high == other_interval.high;
63+
return this.low === other_interval.low && this.high === other_interval.high;
6464
}
6565

6666
/**
@@ -83,13 +83,15 @@ const Interval = class Interval {
8383

8484
/**
8585
* Returns new interval merged with other interval
86-
* @param {Interval} interval - Other interval to merge with
86+
* @param {Interval} other_interval - Other interval to merge with
8787
* @returns {Interval}
8888
*/
8989
merge(other_interval) {
9090
return new Interval(
91-
this.low === undefined ? other_interval.low : Math.min(this.low, other_interval.low),
92-
this.high === undefined ? other_interval.high : Math.max(this.high, other_interval.high)
91+
this.low === undefined ?
92+
other_interval.low : (this.low < other_interval.low ? this.low : other_interval.low),
93+
this.high === undefined ?
94+
other_interval.high : (this.high > other_interval.high ? this.high : other_interval.high)
9395
);
9496
}
9597

0 commit comments

Comments
 (0)