kr11 commented on a change in pull request #1890: URL: https://github.com/apache/iotdb/pull/1890#discussion_r514747722
########## File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/encoder/DiffEncoder.java ########## @@ -0,0 +1,324 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iotdb.tsfile.encoding.encoder; + +import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; +import org.apache.iotdb.tsfile.utils.BytesUtils; +import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * <p> + * DiffEncoder is a encoder for compressing data in type of INT32(integer) and + * INT64(long). It is based in delta-encoding arithmetic.We adapt a hypothesis + * that contiguous data points have similar values.Thus the difference value of + * two adjacent points is smaller than those two point values. One integer in + * java takes 32-bits. If a positive number is less than 2^m, the bits of this + * integer which index from m to 31 are all 0. Given an array which length is n, + * if all values in input data array are all positive and less than 2^m, we need + * actually m*n, but not 32*n bits to store the array. + * </p> + * <p> + * DiffEncoder calculates difference between two adjacent. Then it saves the delta + * value. Then it statistics the longest bit length {@code m} it takes for each + * delta value, which means the bit length that maximum delta value takes. Only + * the low m bits are saved into result byte array for all delta values. + * </p> + */ +public abstract class DiffEncoder extends Encoder { + + protected static final int BLOCK_DEFAULT_SIZE = 128; + private static final Logger logger = LoggerFactory.getLogger(DeltaBinaryEncoder.class); + protected ByteArrayOutputStream out; + protected int blockSize; + // input value is stored in deltaBlackBuffer temporarily + protected byte[] encodingBlockBuffer; + + protected int writeIndex = -1;//defalut value? Review comment: What's the meaning of this annotation? We should explain something, not ask :) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
