File tree Expand file tree Collapse file tree 2 files changed +13
-25
lines changed
Expand file tree Collapse file tree 2 files changed +13
-25
lines changed Original file line number Diff line number Diff line change @@ -102,13 +102,13 @@ Running `npm run bench` with Node v8.10.0:
102102```
1031031000000 rectangles
104104
105- flatbush: 252.311ms
106- 1000 searches 10%: 624.059ms
107- 1000 searches 1%: 76.290ms
108- 1000 searches 0.01%: 8.923ms
109-
110- rbush: 1239.848ms
111- 1000 searches 10%: 973.296ms
112- 1000 searches 1%: 180.831ms
113- 1000 searches 0.01%: 17.746ms
105+ flatbush: 252.849ms
106+ 1000 searches 10%: 617.473ms
107+ 1000 searches 1%: 66.968ms
108+ 1000 searches 0.01%: 7.818ms
109+
110+ rbush: 1083.758ms
111+ 1000 searches 10%: 920.252ms
112+ 1000 searches 1%: 173.104ms
113+ 1000 searches 0.01%: 19.057ms
114114```
Original file line number Diff line number Diff line change @@ -125,12 +125,13 @@ export default class Flatbush {
125125 }
126126
127127 let nodeIndex = this . data . length - 5 ;
128+ let level = this . _levelBounds . length - 1 ;
128129 const queue = [ ] ;
129130 const results = [ ] ;
130131
131132 while ( nodeIndex !== undefined ) {
132133 // find the end index of the node
133- const end = Math . min ( nodeIndex + this . nodeSize * 5 , upperBound ( nodeIndex , this . _levelBounds ) ) ;
134+ const end = Math . min ( nodeIndex + this . nodeSize * 5 , this . _levelBounds [ level ] ) ;
134135
135136 // search through child nodes
136137 for ( let pos = nodeIndex ; pos < end ; pos += 5 ) {
@@ -149,31 +150,18 @@ export default class Flatbush {
149150
150151 } else {
151152 queue . push ( index ) ; // node; add it to the search queue
153+ queue . push ( level - 1 ) ;
152154 }
153155 }
154156
157+ level = queue . pop ( ) ;
155158 nodeIndex = queue . pop ( ) ;
156159 }
157160
158161 return results ;
159162 }
160163}
161164
162- // binary search for the first value in the array bigger than the given
163- function upperBound ( value , arr ) {
164- let i = 0 ;
165- let j = arr . length - 1 ;
166- while ( i < j ) {
167- const m = ( i + j ) >> 1 ;
168- if ( arr [ m ] > value ) {
169- j = m ;
170- } else {
171- i = m + 1 ;
172- }
173- }
174- return arr [ i ] ;
175- }
176-
177165// custom quicksort that sorts bbox data alongside the hilbert values
178166function sort ( values , boxes , left , right ) {
179167 if ( left >= right ) return ;
You can’t perform that action at this time.
0 commit comments