Skip to content

Commit 7fd6d7b

Browse files
committed
reintroduce upper bound routine in search
Possibly slightly faster (2–3%), and more consistent with kNN search.
1 parent d45c378 commit 7fd6d7b

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ export default class Flatbush {
171171
}
172172

173173
let nodeIndex = this._boxes.length - 4;
174-
let level = this._levelBounds.length - 1;
175174
const queue = [];
176175
const results = [];
177176

178177
while (nodeIndex !== undefined) {
179178
// find the end index of the node
180-
const end = Math.min(nodeIndex + this.nodeSize * 4, this._levelBounds[level]);
179+
const end = Math.min(nodeIndex + this.nodeSize * 4, upperBound(nodeIndex, this._levelBounds));
181180

182181
// search through child nodes
183182
for (let pos = nodeIndex; pos < end; pos += 4) {
@@ -196,11 +195,9 @@ export default class Flatbush {
196195

197196
} else {
198197
queue.push(index); // node; add it to the search queue
199-
queue.push(level - 1);
200198
}
201199
}
202200

203-
level = queue.pop();
204201
nodeIndex = queue.pop();
205202
}
206203

0 commit comments

Comments
 (0)