public void serialize()

in spark-load/spark-load-common/src/main/java/org/apache/doris/common/io/Hll.java [238:275]


    public void serialize(DataOutput output) throws IOException {
        switch (type) { // CHECKSTYLE IGNORE THIS LINE: missing switch default
            case HLL_DATA_EMPTY:
                output.writeByte(type);
                break;
            case HLL_DATA_EXPLICIT:
                output.writeByte(type);
                output.writeByte(hashSet.size());
                for (long value : hashSet) {
                    output.writeLong(Long.reverseBytes(value));
                }
                break;
            case HLL_DATA_SPARSE:
            case HLL_DATA_FULL:
                int nonZeroRegisterNum = 0;
                for (int i = 0; i < HLL_REGISTERS_COUNT; i++) {
                    if (registers[i] != 0) {
                        nonZeroRegisterNum++;
                    }
                }
                if (nonZeroRegisterNum > HLL_SPARSE_THRESHOLD) {
                    output.writeByte(HLL_DATA_FULL);
                    for (byte value : registers) {
                        output.writeByte(value);
                    }
                } else {
                    output.writeByte(HLL_DATA_SPARSE);
                    output.writeInt(Integer.reverseBytes(nonZeroRegisterNum));
                    for (int i = 0; i < HLL_REGISTERS_COUNT; i++) {
                        if (registers[i] != 0) {
                            output.writeShort(Short.reverseBytes((short) i));
                            output.writeByte(registers[i]);
                        }
                    }
                }
                break;
        }
    }