public void merge(HllBuffer buffer1, HllBuffer buffer2) {
        int idx = 0;
        int wordOffset = 0;
        while (wordOffset < numWords) {
            long word1 = buffer1.array[wordOffset];
            long word2 = buffer2.array[wordOffset];
            long word = 0L;
            int i = 0;
            long mask = REGISTER_WORD_MASK;
            while (idx < m && i < REGISTERS_PER_WORD) {
                word |= Math.max(word1 & mask, word2 & mask);
                mask <<= REGISTER_SIZE;
                i += 1;
                idx += 1;
            }
            buffer1.array[wordOffset] = word;
            wordOffset += 1;
        }
    }
@Test
    public void testMerge() {
        HyperLogLogPlusPlus hll = new HyperLogLogPlusPlus(0.05);
        HllBuffer buffer1a = createHllBuffer(hll);
        HllBuffer buffer1b = createHllBuffer(hll);
        HllBuffer buffer2 = createHllBuffer(hll);

        // Create the
        // Add the lower half
        int i = 0;
        while (i < 500000) {
            hll.updateByHashcode(buffer1a, hashInt(i, DEFAULT_SEED));
            i += 1;
        }

        // Add the upper half
        i = 500000;
        while (i < 1000000) {
            hll.updateByHashcode(buffer1b, hashInt(i, DEFAULT_SEED));
            i += 1;
        }

        // Merge the lower and upper halves.
        hll.merge(buffer1a, buffer1b);

        // Create the other buffer in reverse
        i = 999999;
        while (i >= 0) {
            hll.updateByHashcode(buffer2, hashInt(i, DEFAULT_SEED));
            i -= 1;
        }

        assertThat(buffer2.array).isEqualTo(buffer1a.array);
    }