@flatten-js/interval-tree
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -9,3 +9,23 @@ 'use strict'; | ||
/** | ||
* Interval is a pair of numbers or a pair of any comparable objects on which may be defined predicates | ||
* *equal*, *less* and method *max(p1, p1)* that returns maximum in a pair. | ||
* When interval is an object rather than pair of numbers, this object should have properties *low*, *high*, *max* | ||
* and implement methods *less_than(), equal_to(), intersect(), not_intersect(), clone(), output()*. | ||
* Two static methods *comparable_max(), comparable_less_than()* define how to compare values in pair. <br/> | ||
* This interface is described in typescript definition file *index.d.ts* | ||
* | ||
* Axis aligned rectangle is an example of such interval. | ||
* We may look at rectangle as an interval between its low left and top right corners. | ||
* See **Box** class in [flatten-js](https://github.com/alexbol99/flatten-js) library as the example | ||
* of Interval interface implementation | ||
* @type {Interval} | ||
*/ | ||
const Interval = class Interval { | ||
/** | ||
* Accept two comparable values and creates new instance of interval | ||
* Predicate Interval.comparable_less(low, high) supposed to return true on these values | ||
* @param low | ||
* @param high | ||
*/ | ||
constructor(low, high) { | ||
@@ -16,2 +36,6 @@ this.low = low; | ||
/** | ||
* Returns maximum value of the interval | ||
* @returns {*|Comparable} | ||
*/ | ||
get max() { | ||
@@ -21,6 +45,7 @@ return this.high; | ||
// interval(low, high) { | ||
// return new Interval(low, high); | ||
// } | ||
/** | ||
* Clone interval | ||
* @returns {Interval} | ||
*/ | ||
clone() { | ||
@@ -30,2 +55,7 @@ return new Interval(this.low, this.high); | ||
/** | ||
* Predicate returns true is this interval less than other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
less_than(other_interval) { | ||
@@ -36,2 +66,7 @@ return this.low < other_interval.low || | ||
/** | ||
* Predicate returns true is this interval equals to other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
equal_to(other_interval) { | ||
@@ -41,2 +76,7 @@ return this.low == other_interval.low && this.high == other_interval.high; | ||
/** | ||
* Predicate returns true if this interval intersects other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
intersect(other_interval) { | ||
@@ -46,2 +86,7 @@ return !this.not_intersect(other_interval); | ||
/** | ||
* Predicate returns true if this interval does not intersect other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
not_intersect(other_interval) { | ||
@@ -51,2 +96,5 @@ return (this.high < other_interval.low || other_interval.high < this.low); | ||
/** | ||
* Returns how key should return | ||
*/ | ||
output() { | ||
@@ -56,7 +104,19 @@ return [this.low, this.high]; | ||
static comparable_max(val1, val2) { | ||
/** | ||
* Function returns maximum between two comparable values | ||
* @param val1 | ||
* @param val2 | ||
* @returns {number} | ||
*/ | ||
comparable_max(val1, val2) { | ||
return Math.max(val1, val2); | ||
} | ||
static comparable_less_than(val1, val2 ) { | ||
/** | ||
* Predicate returns true if first value less than second value | ||
* @param val1 | ||
* @param val2 | ||
* @returns {boolean} | ||
*/ | ||
comparable_less_than(val1, val2 ) { | ||
return val1 < val2; | ||
@@ -132,6 +192,8 @@ } | ||
if (this.right && this.right.max) { | ||
this.max = Interval.comparable_max(this.max, this.right.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.right.max); | ||
} | ||
if (this.left && this.left.max) { | ||
this.max = Interval.comparable_max(this.max, this.left.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.left.max); | ||
} | ||
@@ -142,4 +204,5 @@ } | ||
not_intersect_left_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let high = this.left.max.high ? this.left.max.high : this.left.max; | ||
return Interval.comparable_less_than(high, search_node.item.key.low); | ||
return comparable_less_than(high, search_node.item.key.low); | ||
} | ||
@@ -149,4 +212,5 @@ | ||
not_intersect_right_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let low = this.right.max.low ? this.right.max.low : this.right.item.key.low; | ||
return Interval.comparable_less_than(search_node.item.key.high, low); | ||
return comparable_less_than(search_node.item.key.high, low); | ||
} | ||
@@ -164,5 +228,3 @@ } | ||
* Interval tree stores items which are couples of {key:interval, value: value} <br/> | ||
* Interval is an object with high and low properties or simply array of pairs [low,high] of numeric values <br /> | ||
* If interval is an object, it should implement and expose methods less_than, equals_to, intersect and others, | ||
* see documentation | ||
* Interval is an object with high and low properties or simply pair [low,high] of numeric values <br /> | ||
* @type {IntervalTree} | ||
@@ -169,0 +231,0 @@ */ |
@@ -5,3 +5,23 @@ /** | ||
/** | ||
* Interval is a pair of numbers or a pair of any comparable objects on which may be defined predicates | ||
* *equal*, *less* and method *max(p1, p1)* that returns maximum in a pair. | ||
* When interval is an object rather than pair of numbers, this object should have properties *low*, *high*, *max* | ||
* and implement methods *less_than(), equal_to(), intersect(), not_intersect(), clone(), output()*. | ||
* Two static methods *comparable_max(), comparable_less_than()* define how to compare values in pair. <br/> | ||
* This interface is described in typescript definition file *index.d.ts* | ||
* | ||
* Axis aligned rectangle is an example of such interval. | ||
* We may look at rectangle as an interval between its low left and top right corners. | ||
* See **Box** class in [flatten-js](https://github.com/alexbol99/flatten-js) library as the example | ||
* of Interval interface implementation | ||
* @type {Interval} | ||
*/ | ||
const Interval = class Interval { | ||
/** | ||
* Accept two comparable values and creates new instance of interval | ||
* Predicate Interval.comparable_less(low, high) supposed to return true on these values | ||
* @param low | ||
* @param high | ||
*/ | ||
constructor(low, high) { | ||
@@ -12,2 +32,6 @@ this.low = low; | ||
/** | ||
* Returns maximum value of the interval | ||
* @returns {*|Comparable} | ||
*/ | ||
get max() { | ||
@@ -17,6 +41,7 @@ return this.high; | ||
// interval(low, high) { | ||
// return new Interval(low, high); | ||
// } | ||
/** | ||
* Clone interval | ||
* @returns {Interval} | ||
*/ | ||
clone() { | ||
@@ -26,2 +51,7 @@ return new Interval(this.low, this.high); | ||
/** | ||
* Predicate returns true is this interval less than other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
less_than(other_interval) { | ||
@@ -32,2 +62,7 @@ return this.low < other_interval.low || | ||
/** | ||
* Predicate returns true is this interval equals to other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
equal_to(other_interval) { | ||
@@ -37,2 +72,7 @@ return this.low == other_interval.low && this.high == other_interval.high; | ||
/** | ||
* Predicate returns true if this interval intersects other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
intersect(other_interval) { | ||
@@ -42,2 +82,7 @@ return !this.not_intersect(other_interval); | ||
/** | ||
* Predicate returns true if this interval does not intersect other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
not_intersect(other_interval) { | ||
@@ -47,2 +92,5 @@ return (this.high < other_interval.low || other_interval.high < this.low); | ||
/** | ||
* Returns how key should return | ||
*/ | ||
output() { | ||
@@ -52,7 +100,19 @@ return [this.low, this.high]; | ||
static comparable_max(val1, val2) { | ||
/** | ||
* Function returns maximum between two comparable values | ||
* @param val1 | ||
* @param val2 | ||
* @returns {number} | ||
*/ | ||
comparable_max(val1, val2) { | ||
return Math.max(val1, val2); | ||
} | ||
static comparable_less_than(val1, val2 ) { | ||
/** | ||
* Predicate returns true if first value less than second value | ||
* @param val1 | ||
* @param val2 | ||
* @returns {boolean} | ||
*/ | ||
comparable_less_than(val1, val2 ) { | ||
return val1 < val2; | ||
@@ -128,6 +188,8 @@ } | ||
if (this.right && this.right.max) { | ||
this.max = Interval.comparable_max(this.max, this.right.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.right.max); | ||
} | ||
if (this.left && this.left.max) { | ||
this.max = Interval.comparable_max(this.max, this.left.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.left.max); | ||
} | ||
@@ -138,4 +200,5 @@ } | ||
not_intersect_left_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let high = this.left.max.high ? this.left.max.high : this.left.max; | ||
return Interval.comparable_less_than(high, search_node.item.key.low); | ||
return comparable_less_than(high, search_node.item.key.low); | ||
} | ||
@@ -145,4 +208,5 @@ | ||
not_intersect_right_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let low = this.right.max.low ? this.right.max.low : this.right.item.key.low; | ||
return Interval.comparable_less_than(search_node.item.key.high, low); | ||
return comparable_less_than(search_node.item.key.high, low); | ||
} | ||
@@ -160,5 +224,3 @@ } | ||
* Interval tree stores items which are couples of {key:interval, value: value} <br/> | ||
* Interval is an object with high and low properties or simply array of pairs [low,high] of numeric values <br /> | ||
* If interval is an object, it should implement and expose methods less_than, equals_to, intersect and others, | ||
* see documentation | ||
* Interval is an object with high and low properties or simply pair [low,high] of numeric values <br /> | ||
* @type {IntervalTree} | ||
@@ -165,0 +227,0 @@ */ |
@@ -11,3 +11,23 @@ (function (global, factory) { | ||
/** | ||
* Interval is a pair of numbers or a pair of any comparable objects on which may be defined predicates | ||
* *equal*, *less* and method *max(p1, p1)* that returns maximum in a pair. | ||
* When interval is an object rather than pair of numbers, this object should have properties *low*, *high*, *max* | ||
* and implement methods *less_than(), equal_to(), intersect(), not_intersect(), clone(), output()*. | ||
* Two static methods *comparable_max(), comparable_less_than()* define how to compare values in pair. <br/> | ||
* This interface is described in typescript definition file *index.d.ts* | ||
* | ||
* Axis aligned rectangle is an example of such interval. | ||
* We may look at rectangle as an interval between its low left and top right corners. | ||
* See **Box** class in [flatten-js](https://github.com/alexbol99/flatten-js) library as the example | ||
* of Interval interface implementation | ||
* @type {Interval} | ||
*/ | ||
const Interval = class Interval { | ||
/** | ||
* Accept two comparable values and creates new instance of interval | ||
* Predicate Interval.comparable_less(low, high) supposed to return true on these values | ||
* @param low | ||
* @param high | ||
*/ | ||
constructor(low, high) { | ||
@@ -18,2 +38,6 @@ this.low = low; | ||
/** | ||
* Returns maximum value of the interval | ||
* @returns {*|Comparable} | ||
*/ | ||
get max() { | ||
@@ -23,6 +47,7 @@ return this.high; | ||
// interval(low, high) { | ||
// return new Interval(low, high); | ||
// } | ||
/** | ||
* Clone interval | ||
* @returns {Interval} | ||
*/ | ||
clone() { | ||
@@ -32,2 +57,7 @@ return new Interval(this.low, this.high); | ||
/** | ||
* Predicate returns true is this interval less than other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
less_than(other_interval) { | ||
@@ -38,2 +68,7 @@ return this.low < other_interval.low || | ||
/** | ||
* Predicate returns true is this interval equals to other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
equal_to(other_interval) { | ||
@@ -43,2 +78,7 @@ return this.low == other_interval.low && this.high == other_interval.high; | ||
/** | ||
* Predicate returns true if this interval intersects other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
intersect(other_interval) { | ||
@@ -48,2 +88,7 @@ return !this.not_intersect(other_interval); | ||
/** | ||
* Predicate returns true if this interval does not intersect other interval | ||
* @param other_interval | ||
* @returns {boolean} | ||
*/ | ||
not_intersect(other_interval) { | ||
@@ -53,2 +98,5 @@ return (this.high < other_interval.low || other_interval.high < this.low); | ||
/** | ||
* Returns how key should return | ||
*/ | ||
output() { | ||
@@ -58,7 +106,19 @@ return [this.low, this.high]; | ||
static comparable_max(val1, val2) { | ||
/** | ||
* Function returns maximum between two comparable values | ||
* @param val1 | ||
* @param val2 | ||
* @returns {number} | ||
*/ | ||
comparable_max(val1, val2) { | ||
return Math.max(val1, val2); | ||
} | ||
static comparable_less_than(val1, val2 ) { | ||
/** | ||
* Predicate returns true if first value less than second value | ||
* @param val1 | ||
* @param val2 | ||
* @returns {boolean} | ||
*/ | ||
comparable_less_than(val1, val2 ) { | ||
return val1 < val2; | ||
@@ -134,6 +194,8 @@ } | ||
if (this.right && this.right.max) { | ||
this.max = Interval.comparable_max(this.max, this.right.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.right.max); | ||
} | ||
if (this.left && this.left.max) { | ||
this.max = Interval.comparable_max(this.max, this.left.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.left.max); | ||
} | ||
@@ -144,4 +206,5 @@ } | ||
not_intersect_left_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let high = this.left.max.high ? this.left.max.high : this.left.max; | ||
return Interval.comparable_less_than(high, search_node.item.key.low); | ||
return comparable_less_than(high, search_node.item.key.low); | ||
} | ||
@@ -151,4 +214,5 @@ | ||
not_intersect_right_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let low = this.right.max.low ? this.right.max.low : this.right.item.key.low; | ||
return Interval.comparable_less_than(search_node.item.key.high, low); | ||
return comparable_less_than(search_node.item.key.high, low); | ||
} | ||
@@ -166,5 +230,3 @@ } | ||
* Interval tree stores items which are couples of {key:interval, value: value} <br/> | ||
* Interval is an object with high and low properties or simply array of pairs [low,high] of numeric values <br /> | ||
* If interval is an object, it should implement and expose methods less_than, equals_to, intersect and others, | ||
* see documentation | ||
* Interval is an object with high and low properties or simply pair [low,high] of numeric values <br /> | ||
* @type {IntervalTree} | ||
@@ -171,0 +233,0 @@ */ |
@@ -23,4 +23,4 @@ // Type definitions for flatten-interval-tree library v1.0.2 | ||
static comparable_max(arg1: Comparable, arg2: Comparable) : Comparable; | ||
static comparable_less_than(arg1: Comparable, arg2: Comparable ) : boolean; | ||
comparable_max(arg1: Comparable, arg2: Comparable) : Comparable; | ||
comparable_less_than(arg1: Comparable, arg2: Comparable ) : boolean; | ||
} | ||
@@ -27,0 +27,0 @@ |
{ | ||
"name": "@flatten-js/interval-tree", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Interval search tree", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.cjs.js", |
@@ -29,3 +29,3 @@ # @flatten-js/interval-tree | ||
and implement methods *less_than(), equal_to(), intersect(), not_intersect(), clone(), output()*. | ||
Two static methods *comparable_max(), comparable_less_than()* define how to compare values in pair. <br/> | ||
Two methods *comparable_max(), comparable_less_than()* define how to compare values in pair. <br/> | ||
This interface is described in typescript definition file *index.d.ts* | ||
@@ -32,0 +32,0 @@ |
@@ -98,3 +98,3 @@ /** | ||
*/ | ||
static comparable_max(val1, val2) { | ||
comparable_max(val1, val2) { | ||
return Math.max(val1, val2); | ||
@@ -109,3 +109,3 @@ } | ||
*/ | ||
static comparable_less_than(val1, val2 ) { | ||
comparable_less_than(val1, val2 ) { | ||
return val1 < val2; | ||
@@ -112,0 +112,0 @@ } |
@@ -60,6 +60,8 @@ /** | ||
if (this.right && this.right.max) { | ||
this.max = Interval.comparable_max(this.max, this.right.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.right.max); | ||
} | ||
if (this.left && this.left.max) { | ||
this.max = Interval.comparable_max(this.max, this.left.max); | ||
const comparable_max = this.item.key.comparable_max; | ||
this.max = comparable_max(this.max, this.left.max); | ||
} | ||
@@ -70,4 +72,5 @@ } | ||
not_intersect_left_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let high = this.left.max.high ? this.left.max.high : this.left.max; | ||
return Interval.comparable_less_than(high, search_node.item.key.low); | ||
return comparable_less_than(high, search_node.item.key.low); | ||
} | ||
@@ -77,4 +80,5 @@ | ||
not_intersect_right_subtree(search_node) { | ||
const comparable_less_than = this.item.key.comparable_less_than; | ||
let low = this.right.max.low ? this.right.max.low : this.right.item.key.low; | ||
return Interval.comparable_less_than(search_node.item.key.high, low); | ||
return comparable_less_than(search_node.item.key.high, low); | ||
} | ||
@@ -81,0 +85,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1649446
3914