public DenseHll mergeWith ( DenseHll other ) { if ( indexBitLength != other . indexBitLength ) { throw new IllegalArgumentException ( String . format ( "Cannot merge HLLs with different number of buckets: %s vs %s" , numberOfBuckets ( indexBitLength ) , numberOfBuckets ( other . indexBitLength ) ) ) ; } int baseline = Math . max ( this . baseline , other . baseline ) ; int baselineCount = 0 ; int overflows = 0 ; int [ ] overflowBuckets = new int [ OVERFLOW_GROW_INCREMENT ] ; byte [ ] overflowValues = new byte [ OVERFLOW_GROW_INCREMENT ] ; int numberOfBuckets = numberOfBuckets ( indexBitLength ) ; for ( int i = 0 ; i < numberOfBuckets ; i ++ ) { int value = Math . max ( getValue ( i ) , other . getValue ( i ) ) ; int delta = value - baseline ; if ( delta == 0 ) { baselineCount ++ ; } else if ( delta > MAX_DELTA ) { // grow overflows arrays if necessary overflowBuckets = Ints . ensureCapacity ( overflowBuckets , overflows + 1 , OVERFLOW_GROW_INCREMENT ) ; overflowValues = Bytes . ensureCapacity ( overflowValues , overflows + 1 , OVERFLOW_GROW_INCREMENT ) ; overflowBuckets [ overflows ] = i ; overflowValues [ overflows ] = ( byte ) ( delta - MAX_DELTA ) ; overflows ++ ; delta = MAX_DELTA ; } setDelta ( i , delta ) ; } this . baseline = ( byte ) baseline ; this . baselineCount = baselineCount ; this . overflows = overflows ; this . overflowBuckets = overflowBuckets ; this . overflowValues = overflowValues ; // all baseline values in one of the HLLs lost to the values // in the other HLL, so we need to adjust the final baseline adjustBaselineIfNeeded ( ) ; return this ; }
Returns this for chaining