static final long [ ] compactCache ( final long [ ] srcCache , final int curCount , final long thetaLong , final boolean dstOrdered ) { if ( curCount == 0 ) { return new long [ 0 ] ; } final long [ ] cacheOut = new long [ curCount ] ; final int len = srcCache . length ; int j = 0 ; for ( int i = 0 ; i < len ; i ++ ) { //scan the full srcCache final long v = srcCache [ i ] ; if ( ( v <= 0L ) || ( v >= thetaLong ) ) { continue ; } //ignoring zeros or dirty values cacheOut [ j ++ ] = v ; } assert curCount == j ; if ( dstOrdered && ( curCount > 1 ) ) { Arrays . sort ( cacheOut ) ; } return cacheOut ; }
Compact the given array . The source cache can be a hash table with interstitial zeros or dirty values .