File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -222,4 +222,32 @@ test('reconstructs an index from SharedArrayBuffer', () => {
222222 assert . deepEqual ( index , index2 ) ;
223223} ) ;
224224
225+ test ( 'quicksort should work with an inbalanced dataset' , ( ) => {
226+ const n = 15000
227+ const index = new Flatbush ( 2 * n ) ;
228+
229+ function linspace ( start , stop , num , endpoint = true ) {
230+ const div = endpoint ? ( num - 1 ) : num ;
231+ const step = ( stop - start ) / div ;
232+ return Array . from ( { length : num } , ( _ , i ) => start + step * i ) ;
233+ }
234+
235+ const items = linspace ( 0 , 1000 , n )
236+ const items2 = linspace ( 0 , 1000 , n )
237+
238+ for ( const p of items ) {
239+ index . add ( p , 0 , p , 0 ) ;
240+ }
241+
242+ for ( const p of items2 ) {
243+ index . add ( p , 0 , p , 0 ) ;
244+ }
245+
246+ index . finish ( ) ;
247+
248+ assert . doesNotThrow ( ( ) => {
249+ index . search ( - 100 , - 1 , 15000 , 1 ) ;
250+ } ) ;
251+ } ) ;
252+
225253function compare ( a , b ) { return a - b ; }
You can’t perform that action at this time.
0 commit comments