static void refreshKXP ( final CpcSketch sketch , final long [ ] bitMatrix ) { final int k = ( 1 << sketch . lgK ) ; // for improved numerical accuracy, we separately sum the bytes of the U64's final double [ ] byteSums = new double [ 8 ] ; for ( int j = 0 ; j < 8 ; j ++ ) { byteSums [ j ] = 0.0 ; } for ( int i = 0 ; i < k ; i ++ ) { long row = bitMatrix [ i ] ; for ( int j = 0 ; j < 8 ; j ++ ) { final int byteIdx = ( int ) ( row & 0XFF L ) ; byteSums [ j ] += kxpByteLookup [ byteIdx ] ; row >>>= 8 ; } } double total = 0.0 ; for ( int j = 7 ; j -- > 0 ; ) { // the reverse order is important final double factor = invPow2 ( 8 * j ) ; // pow(256, -j) == pow(2, -8 * j); total += factor * byteSums [ j ] ; } sketch . kxp = total ; }
Also used in test