private static short mergeAndStoreByteRegister ( final ByteBuffer storageBuffer , final int position , final int offsetDiff , final byte byteToAdd ) { if ( byteToAdd == 0 ) { return 0 ; } final byte currVal = storageBuffer . get ( position ) ; final int upperNibble = currVal & 0xf0 ; final int lowerNibble = currVal & 0x0f ; // subtract the differences so that the nibbles align final int otherUpper = ( byteToAdd & 0xf0 ) - ( offsetDiff << bitsPerBucket ) ; final int otherLower = ( byteToAdd & 0x0f ) - offsetDiff ; final int newUpper = Math . max ( upperNibble , otherUpper ) ; final int newLower = Math . max ( lowerNibble , otherLower ) ; storageBuffer . put ( position , ( byte ) ( ( newUpper | newLower ) & 0xff ) ) ; short numNoLongerZero = 0 ; if ( upperNibble == 0 && newUpper > 0 ) { ++ numNoLongerZero ; } if ( lowerNibble == 0 && newLower > 0 ) { ++ numNoLongerZero ; } return numNoLongerZero ; }
Returns the number of registers that are no longer zero after the value was added