private void search ( double [ ] q , Node node , double radius , List < Neighbor < double [ ] , E > > neighbors ) { if ( node . isLeaf ( ) ) { // look at all the instances in this leaf for ( int idx = node . index ; idx < node . index + node . count ; idx ++ ) { if ( q == keys [ index [ idx ] ] && identicalExcluded ) { continue ; } double distance = Math . distance ( q , keys [ index [ idx ] ] ) ; if ( distance <= radius ) { neighbors . add ( new Neighbor <> ( keys [ index [ idx ] ] , data [ index [ idx ] ] , index [ idx ] , distance ) ) ; } } } else { Node nearer , further ; double diff = q [ node . split ] - node . cutoff ; if ( diff < 0 ) { nearer = node . lower ; further = node . upper ; } else { nearer = node . upper ; further = node . lower ; } search ( q , nearer , radius , neighbors ) ; // now look in further half if ( radius >= Math . abs ( diff ) ) { search ( q , further , radius , neighbors ) ; } } }
Returns the neighbors in the given range of search target from the give tree node .