Skip to content

Commit

Permalink
fix: finds the lowest intersecting interval #47
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbol99 committed Sep 17, 2023
1 parent 45bcbbf commit 0b3e296
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions dist/main.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class IntervalTree {
}

/**
* @param {Interval} interval - optional if the iterator is intended to start from the beginning or end
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
* @returns {Iterator}
*/
Expand Down Expand Up @@ -657,8 +657,12 @@ class IntervalTree {
let curr = node;
while (curr && curr != this.nil_node) {
if (curr.less_than(search_node)) {
if (curr.intersect(search_node) && (!best || curr.less_than(best))) best = curr;
curr = curr.right;
if (curr.intersect(search_node)) {
best = curr;
curr = curr.left;
} else {
curr = curr.right;
}
} else {
if (!best || curr.less_than(best)) best = curr;
curr = curr.left;
Expand Down
10 changes: 7 additions & 3 deletions dist/main.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class IntervalTree {
}

/**
* @param {Interval} interval - optional if the iterator is intended to start from the beginning or end
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
* @returns {Iterator}
*/
Expand Down Expand Up @@ -653,8 +653,12 @@ class IntervalTree {
let curr = node;
while (curr && curr != this.nil_node) {
if (curr.less_than(search_node)) {
if (curr.intersect(search_node) && (!best || curr.less_than(best))) best = curr;
curr = curr.right;
if (curr.intersect(search_node)) {
best = curr;
curr = curr.left;
} else {
curr = curr.right;
}
} else {
if (!best || curr.less_than(best)) best = curr;
curr = curr.left;
Expand Down
10 changes: 7 additions & 3 deletions dist/main.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
}

/**
* @param {Interval} interval - optional if the iterator is intended to start from the beginning or end
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
* @returns {Iterator}
*/
Expand Down Expand Up @@ -659,8 +659,12 @@
let curr = node;
while (curr && curr != this.nil_node) {
if (curr.less_than(search_node)) {
if (curr.intersect(search_node) && (!best || curr.less_than(best))) best = curr;
curr = curr.right;
if (curr.intersect(search_node)) {
best = curr;
curr = curr.left;
} else {
curr = curr.right;
}
} else {
if (!best || curr.less_than(best)) best = curr;
curr = curr.left;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flatten-js/interval-tree",
"version": "1.1.0",
"version": "1.1.1",
"description": "Interval search tree",
"author": "Alex Bol",
"license": "MIT",
Expand Down

0 comments on commit 0b3e296

Please sign in to comment.