kangpinghuang commented on a change in pull request #1633: add zone map 
page(#1390)
URL: https://github.com/apache/incubator-doris/pull/1633#discussion_r316647781
 
 

 ##########
 File path: be/src/olap/rowset/segment_v2/row_ranges.h
 ##########
 @@ -0,0 +1,303 @@
+// 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.
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "common/logging.h"
+#include "olap/rowset/segment_v2/common.h"
+#include "gutil/strings/substitute.h"
+
+namespace doris {
+namespace segment_v2 {
+
+// RowRange stands for range[From, To), From is inclusive,
+// To is exclusive. It is used for row id range calculation.
+class RowRange {
+public:
+    // Returns true if if two ranges are overlapped or false.
+    // The union range will be returned through range.
+    static bool range_union(const RowRange& left, const RowRange& right, 
RowRange* range) {
+        if (left._from <= right._from) {
+            if (left._to >= right._from) {
+                range->_from = left._from;
+                range->_to = std::max(left._to, right._to);
+                return true;
+            }
+        } else if (right._to >= left._from) {
+            range->_from = right._from;
+            range->_to = std::max(left._to, right._to);
+            return true;
+        }
+        // return a invalid range
+        range->_from = 0;
+        range->_to = 0;
+        return false;
+    }
+
+    // Returns true if the two ranges are overlapped or false.
+    // The intersection of the two ranges is returned through range.
+    static bool range_intersection(const RowRange& left, const RowRange& 
right, RowRange* range) {
+        if (left._from <= right._from) {
+            if (left._to > right._from) {
+                range->_from = right._from;
+                range->_to = std::min(left._to, right._to);
+                return true;
+            }
+        } else if (right._to > left._from) {
+            range->_from = left._from;
+            range->_to = std::min(left._to, right._to);
+            return true;
+        }
+        // return a invalid range
+        range->_from = 0;
+        range->_to = 0;
+        return false;
+    }
+
+    RowRange() : _from(0), _to(0) { }
+
+    RowRange(const RowRange& other) : _from(other._from), _to(other._to) { }
+
+    RowRange& operator=(const RowRange& other) {
+        _from = other._from;
+        _to = other._to;
+        return *this;
+    }
+
+    // Creates a range of [from, to) (from inclusive and to exclusive; empty 
ranges are invalid)
+    RowRange(int64_t from, int64_t to) : _from(from), _to(to) { }
+
+    bool is_valid() const {
+        return _from < _to;
+    }
+
+    size_t count() const {
+        return _to - _from;
+    }
+
+    bool is_before(const RowRange& other) const {
+        return _to <= other._from;
+    }
+
+    bool is_after(const RowRange& other) const {
+        return _from >= other._to;
+    }
+
+    int64_t from() const {
+        return _from;
+    }
+
+    int64_t to() const {
+        return _to;
+    }
+
+    std::string to_string() const {
+        return strings::Substitute("[$0-$1]", _from, _to);
+    }
+
+private:
+    int64_t _from;
+    int64_t _to;
+};
+
+class RowRanges {
+public:
+    RowRanges() { }
+
+    RowRanges(RowRanges&& other) : _ranges(std::move(other._ranges)) { }
+
+    RowRanges& operator=(RowRanges&& other) {
+        if (this != &other) {
+            _ranges = std::move(other._ranges);
+        }
+        return *this;
+    }
+
+    // Creates a new RowRanges object with the single range [0, row_count).
+    static RowRanges create_single(uint64_t row_count) {
+        RowRanges ranges;
+        ranges.add(RowRange(0, row_count));
+        return ranges;
+    }
+
+    // Creates a new RowRanges object with the single range [from, to).
+    static RowRanges create_single(int64_t from, int64_t to) {
+        DCHECK(from <= to);
+        RowRanges ranges;
+        ranges.add(RowRange(from, to));
+        return ranges;
+    }
+
+    
+    // Calculates the union of the two specified RowRanges object. The union 
of two range is calculated if there are
+    // elements between them. Otherwise, the two disjunct ranges are stored 
separately.
+    // For example:
+    // [113, 241] ∪ [221, 340] = [113, 330]
+    // [113, 230] ∪ [231, 340] = [113, 340]
+    // while
+    // [113, 230] ∪ [232, 340] = [113, 230], [232, 340]
 
 Review comment:
   ok

----------------------------------------------------------------
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: dev-unsubscr...@doris.apache.org
For additional commands, e-mail: dev-h...@doris.apache.org

Reply via email to