private final boolean updateHll ( final int entryIndex , final int coupon ) { final int newValue = coupon16Value ( coupon ) ; final int hllIdx = coupon & ( k_ - 1 ) ; //lower lgK bits final int longIdx = hllIdx / 10 ; final int shift = ( ( hllIdx % 10 ) * 6 ) & SIX_BIT_MASK ; long hllLong = arrOfHllArr_ [ ( entryIndex * hllArrLongs_ ) + longIdx ] ; final int oldValue = ( int ) ( hllLong >>> shift ) & SIX_BIT_MASK ; if ( newValue <= oldValue ) { return false ; } // newValue > oldValue //update hipEstAccum BEFORE updating invPow2Sum final double invPow2Sum = invPow2SumHiArr_ [ entryIndex ] + invPow2SumLoArr_ [ entryIndex ] ; final double oneOverQ = k_ / invPow2Sum ; hipEstAccumArr_ [ entryIndex ] += oneOverQ ; //update invPow2Sum if ( oldValue < 32 ) { invPow2SumHiArr_ [ entryIndex ] -= invPow2 ( oldValue ) ; } else { invPow2SumLoArr_ [ entryIndex ] -= invPow2 ( oldValue ) ; } if ( newValue < 32 ) { invPow2SumHiArr_ [ entryIndex ] += invPow2 ( newValue ) ; } else { invPow2SumLoArr_ [ entryIndex ] += invPow2 ( newValue ) ; } //insert the new value hllLong &= ~ ( 0X3F L << shift ) ; //zero out the 6-bit field hllLong |= ( ( long ) newValue ) << shift ; //insert arrOfHllArr_ [ ( entryIndex * hllArrLongs_ ) + longIdx ] = hllLong ; return true ; }
This method is specifically tied to the HLL array layout