public static CompactSketch union(CompactSketch skA,CompactSketch skB){
  final short seedHash=checkOrderedAndSeedHash(skA,skB);
  long thetaLong=Math.min(skA.getThetaLong(),skB.getThetaLong());
  int indexA=0;
  int indexB=0;
  int outCount=0;
  long[] cacheA=skA.getCache();
  long[] cacheB=skB.getCache();
  long[] outCache=new long[cacheA.length + cacheB.length];
  while ((indexA < cacheA.length) || (indexB < cacheB.length)) {
    long hashA=(indexA >= cacheA.length) ? thetaLong : cacheA[indexA];
    long hashB=(indexB >= cacheB.length) ? thetaLong : cacheB[indexB];
    if (hashA >= thetaLong && hashB >= thetaLong) {
      break;
    }
    if (hashA == hashB) {
      outCache[outCount++]=hashA;
      ++indexA;
      ++indexB;
    }
 else     if (hashA < hashB) {
      outCache[outCount++]=hashA;
      ++indexA;
    }
 else {
      outCache[outCount++]=hashB;
      ++indexB;
    }
  }
  boolean empty=skA.isEmpty() && skB.isEmpty();
  return new HeapCompactOrderedSketch(Arrays.copyOf(outCache,outCount),empty,seedHash,outCount,thetaLong);
}

public static CompactSketch union ( CompactSketch skA , CompactSketch skB ) { final short seedHash = checkOrderedAndSeedHash ( skA , skB ) ; long thetaLong = Math . min ( skA . getThetaLong ( ) , skB . getThetaLong ( ) ) ; int indexA = 0 ; int indexB = 0 ; int outCount = 0 ; long [ ] cacheA = skA . getCache ( ) ; long [ ] cacheB = skB . getCache ( ) ; long [ ] outCache = new long [ cacheA . length + cacheB . length ] ; while ( ( indexA < cacheA . length ) || ( indexB < cacheB . length ) ) { long hashA = ( indexA >= cacheA . length ) ? thetaLong : cacheA [ indexA ] ; long hashB = ( indexB >= cacheB . length ) ? thetaLong : cacheB [ indexB ] ; if ( hashA >= thetaLong && hashB >= thetaLong ) { break ; } if ( hashA == hashB ) { outCache [ outCount ++ ] = hashA ; ++ indexA ; ++ indexB ; } else if ( hashA < hashB ) { outCache [ outCount ++ ] = hashA ; ++ indexA ; } else { outCache [ outCount ++ ] = hashB ; ++ indexB ; } } boolean empty = skA . isEmpty ( ) && skB . isEmpty ( ) ; return new HeapCompactOrderedSketch ( Arrays . copyOf ( outCache , outCount ) , empty , seedHash , outCount , thetaLong ) ; }
this implements a stateless , pair - wise union operation on ordered , compactsketches that are either heap - based or direct .
