kangkaisen commented on a change in pull request #1818: Add frame_of_reference 
page
URL: https://github.com/apache/incubator-doris/pull/1818#discussion_r325982090
 
 

 ##########
 File path: be/src/util/frame_of_reference_coding.h
 ##########
 @@ -0,0 +1,147 @@
+// 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.
+
+#ifndef DORIS_FRAME_OF_REFERENCE_CODING_H
+#define DORIS_FRAME_OF_REFERENCE_CODING_H
+
+
+#include <cstdlib>
+#include <iostream>
+
+#include "util/bit_stream_utils.h"
+#include "util/bit_stream_utils.inline.h"
+#include "util/faststring.h"
+
+namespace doris {
+
+struct ForCoding {
+    const static uint8_t BYTE_SIZE = 8;
+    const static uint8_t INT32_SIZE = 8 * 4;
+    const static uint8_t FRAME_VALUE_NUM = 128;
+};
+
+// The implementation for frame-of-reference coding
+// The detail of frame-of-reference coding, please refer to
+// 
https://lemire.me/blog/2012/02/08/effective-compression-using-frame-of-reference-and-delta-coding/
+// and https://www.elastic.co/cn/blog/frame-of-reference-and-roaring-bitmaps
+
+// The encoded data format is as follows:
+
+// 1. Body:
+// BitPackingFrame * FrameCount
+// 2. Footer:
+// FrameOffset(4) * (FrameCount + 1)
+// LastFrameNumValues(1) (optional)
+// FrameCount(4)
+// NumValues(4)
+
+// The BitPackingFrame format is as follows:
+// MinValue, (Value - MinVale) * FRAME_VALUE_NUM
+
+// The last frame value num maybe less than 128
+template<typename T>
+class ForEncoder {
+public:
+    explicit ForEncoder(faststring *buffer): _bit_writer(buffer) {
+    }
+
+    void put(const T value) {
+        return put_batch(&value, 1);
+    }
+
+    void put_batch(const T* value, size_t count);
+
+    // Flushes any pending values to the underlying buffer.
+    // Returns the total number of bytes written
+    uint32_t flush();
+
+    uint32_t len() {
+        return _bit_writer.bytes_written();
+    }
+
+    // Resets all the state in the encoder.
+    void clear() {
+        _count = 0;
+        _frame_count = 0;
+        _buffered_values_num = 0;
+        _bit_writer.Clear();
+        _frame_offsets.clear();
+    }
+
+private:
 
 Review comment:
   Doris codestyle don't have this convention currently.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to