private BoundedPriorityQueue < Result > computeKnnADC ( int k , double [ ] qVector ) { BoundedPriorityQueue < Result > nn = new BoundedPriorityQueue < Result > ( new Result ( ) , k ) ; // apply a random transformation if needed if ( transformation == TransformationType . RandomRotation ) { qVector = rr . rotate ( qVector ) ; } else if ( transformation == TransformationType . RandomPermutation ) { qVector = rp . permute ( qVector ) ; } // compute the lookup table double [ ] [ ] lookUpTable = computeLookupADC ( qVector ) ; for ( int i = 0 ; i < loadCounter ; i ++ ) { double l2distance = 0 ; int codeStart = i * numSubVectors ; if ( numProductCentroids <= 256 ) { byte [ ] pqCode = pqByteCodes . toArray ( codeStart , numSubVectors ) ; for ( int j = 0 ; j < pqCode . length ; j ++ ) { // plus 128 because byte range is -128..127 l2distance += lookUpTable [ j ] [ pqCode [ j ] + 128 ] ; } } else { short [ ] pqCode = pqShortCodes . toArray ( codeStart , numSubVectors ) ; for ( int j = 0 ; j < pqCode . length ; j ++ ) { l2distance += lookUpTable [ j ] [ pqCode [ j ] ] ; } } nn . offer ( new Result ( i , l2distance ) ) ; } return nn ; }
Computes and returns the k nearest neighbors of the query vector using the ADC approach .