public static void mergeBitMaps(ByteBufferReader reader,
                                    ByteBufferWriter mergeBitmapWriter,
                                    int bitCount,
                                    int bitmapCount,
                                    int mergeSlot) throws IOException {
        Preconditions.checkState(mergeSlot <= bitmapCount);

        if (mergeSlot == 0) {
            return;
        }

        DirectBitMap bitmap = new DirectBitMap(bitCount);
        ByteBuffer buffer = (ByteBuffer) bitmap.attach;

        int curSlotIndex = 0;
        int from = 0;
        int bitmapId = 0;
        for (; bitmapId < bitmapCount; bitmapId++) {
            int mergeSlotIndex = idToMergeSlotId(mergeSlot, bitmapCount, bitmapId);
            if (mergeSlotIndex != curSlotIndex) {
                assert curSlotIndex == mergeSlotIndex - 1;

                readAndMergeBitmaps(reader, bitmap, from, bitmapId);

                mergeBitmapWriter.write(buffer);
                buffer.clear();
                bitmap.clear();

                from = bitmapId;
                curSlotIndex = mergeSlotIndex;
            }
        }

        readAndMergeBitmaps(reader, bitmap, from, bitmapId);

        mergeBitmapWriter.write(buffer);
        bitmap.free();
    }
Merge bitmaps together, splited by mergeSlot.
indexr-vlt-segment/src/main/java/io/indexr/vlt/segment/index/MergeBitMapUtil.java