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

 ##########
 File path: be/src/util/frame_of_reference_coding.cpp
 ##########
 @@ -0,0 +1,377 @@
+// 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.
+
+#include "util/frame_of_reference_coding.h"
+
+#include <algorithm>
+#include <cstring>
+
+#include "util/bit_util.h"
+#include "util/coding.h"
+
+namespace doris {
+
+static inline uint8_t bits(const uint64_t v) {
+    return v == 0 ? 0 : 64 - __builtin_clzll(v);
+}
+
+template<typename T>
+const T* ForEncoder<T>::copy_value(const T* in_data, size_t count) {
+    memcpy(&_buffered_values[_buffered_values_num], in_data, count * 
sizeof(T));
+    _buffered_values_num += count;
+    in_data += count;
+    return in_data;
+}
+
+template<typename T>
+void ForEncoder<T>::put_batch(const T* in_data, size_t count) {
+    if (_buffered_values_num + count < ForCoding::FRAME_VALUE_NUM) {
+        copy_value(in_data, count);
+        _count += count;
+        return;
+    }
+
+    // 1. padding one frame
+    size_t padding_num = ForCoding::FRAME_VALUE_NUM - _buffered_values_num;
+    in_data = copy_value(in_data, padding_num);
+    bit_packing_one_frame_value(_buffered_values);
+
+    // 2. process frame by frame
+    size_t frame_size = (count - padding_num) / ForCoding::FRAME_VALUE_NUM;
+    for (size_t i = 0; i < frame_size; i++) {
+        // directly encode value to the bit_writer, don't buffer the value
+        _buffered_values_num = ForCoding::FRAME_VALUE_NUM;
+        bit_packing_one_frame_value(in_data);
+        in_data += ForCoding::FRAME_VALUE_NUM;
+    }
+
+    // 3. process remaining value
+    size_t remaining_num = (count - padding_num) % ForCoding::FRAME_VALUE_NUM;
+    if (remaining_num > 0) {
+        copy_value(in_data, remaining_num);
+    }
+
+    _count += count;
+}
+
+// todo(kks): improve this method by SIMD instructions
+
+// Use as few bit as possible to store a piece of integer data.
+// param[in] input: the integer list need to pack
+// param[in] in_num: the number integer need to pack
+// param[in] bit_width: how many bit we use to store each integer data
+// param[out] out: the packed result
+
 
 Review comment:
   ```suggestion
   //
   ```
   instead of empty line to separate comment block

----------------------------------------------------------------
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