/root/doris/be/src/util/counts.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <pdqsort.h> |
21 | | |
22 | | #include <algorithm> |
23 | | #include <cmath> |
24 | | #include <queue> |
25 | | |
26 | | #include "core/pod_array.h" |
27 | | #include "core/string_buffer.hpp" |
28 | | #include "util/io_helper.h" |
29 | | |
30 | | namespace doris { |
31 | | |
32 | | template <typename Ty> |
33 | | class Counts { |
34 | | public: |
35 | 3.41k | Counts() = default; Line | Count | Source | 35 | 49 | Counts() = default; |
Line | Count | Source | 35 | 219 | Counts() = default; |
Line | Count | Source | 35 | 2.00k | Counts() = default; |
Line | Count | Source | 35 | 835 | Counts() = default; |
Line | Count | Source | 35 | 45 | Counts() = default; |
Line | Count | Source | 35 | 15 | Counts() = default; |
Line | Count | Source | 35 | 248 | Counts() = default; |
|
36 | | |
37 | 1.18k | void merge(Counts* other) { |
38 | 1.18k | if (other != nullptr && !other->_nums.empty()) { |
39 | 1.18k | _sorted_nums_vec.emplace_back(std::move(other->_nums)); |
40 | 1.18k | } |
41 | 1.18k | } _ZN5doris6CountsIaE5mergeEPS1_ Line | Count | Source | 37 | 6 | void merge(Counts* other) { | 38 | 6 | if (other != nullptr && !other->_nums.empty()) { | 39 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 6 | } | 41 | 6 | } |
_ZN5doris6CountsIsE5mergeEPS1_ Line | Count | Source | 37 | 18 | void merge(Counts* other) { | 38 | 18 | if (other != nullptr && !other->_nums.empty()) { | 39 | 18 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 18 | } | 41 | 18 | } |
_ZN5doris6CountsIiE5mergeEPS1_ Line | Count | Source | 37 | 722 | void merge(Counts* other) { | 38 | 722 | if (other != nullptr && !other->_nums.empty()) { | 39 | 722 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 722 | } | 41 | 722 | } |
_ZN5doris6CountsIlE5mergeEPS1_ Line | Count | Source | 37 | 350 | void merge(Counts* other) { | 38 | 350 | if (other != nullptr && !other->_nums.empty()) { | 39 | 350 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 350 | } | 41 | 350 | } |
_ZN5doris6CountsInE5mergeEPS1_ Line | Count | Source | 37 | 6 | void merge(Counts* other) { | 38 | 6 | if (other != nullptr && !other->_nums.empty()) { | 39 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 6 | } | 41 | 6 | } |
_ZN5doris6CountsIfE5mergeEPS1_ Line | Count | Source | 37 | 6 | void merge(Counts* other) { | 38 | 6 | if (other != nullptr && !other->_nums.empty()) { | 39 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 6 | } | 41 | 6 | } |
_ZN5doris6CountsIdE5mergeEPS1_ Line | Count | Source | 37 | 80 | void merge(Counts* other) { | 38 | 80 | if (other != nullptr && !other->_nums.empty()) { | 39 | 80 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 80 | } | 41 | 80 | } |
|
42 | | |
43 | | void increment(Ty key, uint32_t i) { |
44 | | auto old_size = _nums.size(); |
45 | | _nums.resize(_nums.size() + i); |
46 | | for (uint32_t j = 0; j < i; ++j) { |
47 | | _nums[old_size + j] = key; |
48 | | } |
49 | | } |
50 | | |
51 | 2.93k | void increment(Ty key) { _nums.push_back(key); }_ZN5doris6CountsIaE9incrementEa Line | Count | Source | 51 | 73 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIsE9incrementEs Line | Count | Source | 51 | 552 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIiE9incrementEi Line | Count | Source | 51 | 1.59k | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIlE9incrementEl Line | Count | Source | 51 | 401 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsInE9incrementEn Line | Count | Source | 51 | 45 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIfE9incrementEf Line | Count | Source | 51 | 9 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIdE9incrementEd Line | Count | Source | 51 | 259 | void increment(Ty key) { _nums.push_back(key); } |
|
52 | | |
53 | 5 | void increment_batch(const PaddedPODArray<Ty>& keys) { _nums.insert(keys.begin(), keys.end()); }Unexecuted instantiation: _ZN5doris6CountsIaE15increment_batchERKNS_8PODArrayIaLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIsE15increment_batchERKNS_8PODArrayIsLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIiE15increment_batchERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE _ZN5doris6CountsIlE15increment_batchERKNS_8PODArrayIlLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Line | Count | Source | 53 | 5 | void increment_batch(const PaddedPODArray<Ty>& keys) { _nums.insert(keys.begin(), keys.end()); } |
Unexecuted instantiation: _ZN5doris6CountsInE15increment_batchERKNS_8PODArrayInLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIfE15increment_batchERKNS_8PODArrayIfLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIdE15increment_batchERKNS_8PODArrayIdLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE |
54 | | |
55 | 1.60k | void serialize(BufferWritable& buf) { |
56 | 1.60k | if (!_nums.empty()) { |
57 | 1.30k | pdqsort(_nums.begin(), _nums.end()); |
58 | 1.30k | size_t size = _nums.size(); |
59 | 1.30k | buf.write_binary(size); |
60 | 1.30k | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); |
61 | 1.30k | } else { |
62 | | // convert _sorted_nums_vec to _nums and do seiralize again |
63 | 298 | _convert_sorted_num_vec_to_nums(); |
64 | 298 | serialize(buf); |
65 | 298 | } |
66 | 1.60k | } _ZN5doris6CountsIaE9serializeERNS_14BufferWritableE Line | Count | Source | 55 | 6 | void serialize(BufferWritable& buf) { | 56 | 6 | if (!_nums.empty()) { | 57 | 6 | pdqsort(_nums.begin(), _nums.end()); | 58 | 6 | size_t size = _nums.size(); | 59 | 6 | buf.write_binary(size); | 60 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 61 | 6 | } else { | 62 | | // convert _sorted_nums_vec to _nums and do seiralize again | 63 | 0 | _convert_sorted_num_vec_to_nums(); | 64 | 0 | serialize(buf); | 65 | 0 | } | 66 | 6 | } |
_ZN5doris6CountsIsE9serializeERNS_14BufferWritableE Line | Count | Source | 55 | 18 | void serialize(BufferWritable& buf) { | 56 | 18 | if (!_nums.empty()) { | 57 | 18 | pdqsort(_nums.begin(), _nums.end()); | 58 | 18 | size_t size = _nums.size(); | 59 | 18 | buf.write_binary(size); | 60 | 18 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 61 | 18 | } else { | 62 | | // convert _sorted_nums_vec to _nums and do seiralize again | 63 | 0 | _convert_sorted_num_vec_to_nums(); | 64 | 0 | serialize(buf); | 65 | 0 | } | 66 | 18 | } |
_ZN5doris6CountsIiE9serializeERNS_14BufferWritableE Line | Count | Source | 55 | 995 | void serialize(BufferWritable& buf) { | 56 | 995 | if (!_nums.empty()) { | 57 | 839 | pdqsort(_nums.begin(), _nums.end()); | 58 | 839 | size_t size = _nums.size(); | 59 | 839 | buf.write_binary(size); | 60 | 839 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 61 | 839 | } else { | 62 | | // convert _sorted_nums_vec to _nums and do seiralize again | 63 | 156 | _convert_sorted_num_vec_to_nums(); | 64 | 156 | serialize(buf); | 65 | 156 | } | 66 | 995 | } |
_ZN5doris6CountsIlE9serializeERNS_14BufferWritableE Line | Count | Source | 55 | 492 | void serialize(BufferWritable& buf) { | 56 | 492 | if (!_nums.empty()) { | 57 | 350 | pdqsort(_nums.begin(), _nums.end()); | 58 | 350 | size_t size = _nums.size(); | 59 | 350 | buf.write_binary(size); | 60 | 350 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 61 | 350 | } else { | 62 | | // convert _sorted_nums_vec to _nums and do seiralize again | 63 | 142 | _convert_sorted_num_vec_to_nums(); | 64 | 142 | serialize(buf); | 65 | 142 | } | 66 | 492 | } |
_ZN5doris6CountsInE9serializeERNS_14BufferWritableE Line | Count | Source | 55 | 6 | void serialize(BufferWritable& buf) { | 56 | 6 | if (!_nums.empty()) { | 57 | 6 | pdqsort(_nums.begin(), _nums.end()); | 58 | 6 | size_t size = _nums.size(); | 59 | 6 | buf.write_binary(size); | 60 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 61 | 6 | } else { | 62 | | // convert _sorted_nums_vec to _nums and do seiralize again | 63 | 0 | _convert_sorted_num_vec_to_nums(); | 64 | 0 | serialize(buf); | 65 | 0 | } | 66 | 6 | } |
_ZN5doris6CountsIfE9serializeERNS_14BufferWritableE Line | Count | Source | 55 | 6 | void serialize(BufferWritable& buf) { | 56 | 6 | if (!_nums.empty()) { | 57 | 6 | pdqsort(_nums.begin(), _nums.end()); | 58 | 6 | size_t size = _nums.size(); | 59 | 6 | buf.write_binary(size); | 60 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 61 | 6 | } else { | 62 | | // convert _sorted_nums_vec to _nums and do seiralize again | 63 | 0 | _convert_sorted_num_vec_to_nums(); | 64 | 0 | serialize(buf); | 65 | 0 | } | 66 | 6 | } |
_ZN5doris6CountsIdE9serializeERNS_14BufferWritableE Line | Count | Source | 55 | 80 | void serialize(BufferWritable& buf) { | 56 | 80 | if (!_nums.empty()) { | 57 | 80 | pdqsort(_nums.begin(), _nums.end()); | 58 | 80 | size_t size = _nums.size(); | 59 | 80 | buf.write_binary(size); | 60 | 80 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 61 | 80 | } else { | 62 | | // convert _sorted_nums_vec to _nums and do seiralize again | 63 | 0 | _convert_sorted_num_vec_to_nums(); | 64 | 0 | serialize(buf); | 65 | 0 | } | 66 | 80 | } |
|
67 | | |
68 | 1.18k | void unserialize(BufferReadable& buf) { |
69 | 1.18k | size_t size; |
70 | 1.18k | buf.read_binary(size); |
71 | 1.18k | _nums.resize(size); |
72 | 1.18k | auto buff = buf.read(sizeof(Ty) * size); |
73 | 1.18k | memcpy(_nums.data(), buff.data, buff.size); |
74 | 1.18k | } _ZN5doris6CountsIaE11unserializeERNS_14BufferReadableE Line | Count | Source | 68 | 6 | void unserialize(BufferReadable& buf) { | 69 | 6 | size_t size; | 70 | 6 | buf.read_binary(size); | 71 | 6 | _nums.resize(size); | 72 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 73 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 74 | 6 | } |
_ZN5doris6CountsIsE11unserializeERNS_14BufferReadableE Line | Count | Source | 68 | 18 | void unserialize(BufferReadable& buf) { | 69 | 18 | size_t size; | 70 | 18 | buf.read_binary(size); | 71 | 18 | _nums.resize(size); | 72 | 18 | auto buff = buf.read(sizeof(Ty) * size); | 73 | 18 | memcpy(_nums.data(), buff.data, buff.size); | 74 | 18 | } |
_ZN5doris6CountsIiE11unserializeERNS_14BufferReadableE Line | Count | Source | 68 | 722 | void unserialize(BufferReadable& buf) { | 69 | 722 | size_t size; | 70 | 722 | buf.read_binary(size); | 71 | 722 | _nums.resize(size); | 72 | 722 | auto buff = buf.read(sizeof(Ty) * size); | 73 | 722 | memcpy(_nums.data(), buff.data, buff.size); | 74 | 722 | } |
_ZN5doris6CountsIlE11unserializeERNS_14BufferReadableE Line | Count | Source | 68 | 350 | void unserialize(BufferReadable& buf) { | 69 | 350 | size_t size; | 70 | 350 | buf.read_binary(size); | 71 | 350 | _nums.resize(size); | 72 | 350 | auto buff = buf.read(sizeof(Ty) * size); | 73 | 350 | memcpy(_nums.data(), buff.data, buff.size); | 74 | 350 | } |
_ZN5doris6CountsInE11unserializeERNS_14BufferReadableE Line | Count | Source | 68 | 6 | void unserialize(BufferReadable& buf) { | 69 | 6 | size_t size; | 70 | 6 | buf.read_binary(size); | 71 | 6 | _nums.resize(size); | 72 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 73 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 74 | 6 | } |
_ZN5doris6CountsIfE11unserializeERNS_14BufferReadableE Line | Count | Source | 68 | 6 | void unserialize(BufferReadable& buf) { | 69 | 6 | size_t size; | 70 | 6 | buf.read_binary(size); | 71 | 6 | _nums.resize(size); | 72 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 73 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 74 | 6 | } |
_ZN5doris6CountsIdE11unserializeERNS_14BufferReadableE Line | Count | Source | 68 | 80 | void unserialize(BufferReadable& buf) { | 69 | 80 | size_t size; | 70 | 80 | buf.read_binary(size); | 71 | 80 | _nums.resize(size); | 72 | 80 | auto buff = buf.read(sizeof(Ty) * size); | 73 | 80 | memcpy(_nums.data(), buff.data, buff.size); | 74 | 80 | } |
|
75 | | |
76 | 1.10k | double terminate(double quantile) { |
77 | 1.10k | if (_sorted_nums_vec.size() <= 1) { |
78 | 985 | if (_sorted_nums_vec.size() == 1) { |
79 | 332 | _nums = std::move(_sorted_nums_vec[0]); |
80 | 332 | } |
81 | | |
82 | 985 | if (_nums.empty()) { |
83 | | // Although set null here, but the value is 0.0 and the call method just |
84 | | // get val in aggregate_function_percentile_approx.h |
85 | 0 | return 0.0; |
86 | 0 | } |
87 | | |
88 | 985 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { |
89 | 180 | pdqsort(_nums.begin(), _nums.end()); |
90 | 180 | } |
91 | | |
92 | 985 | if (quantile == 1 || _nums.size() == 1) { |
93 | 473 | return _nums.back(); |
94 | 473 | } |
95 | | |
96 | 512 | double u = (_nums.size() - 1) * quantile; |
97 | 512 | auto index = static_cast<uint32_t>(u); |
98 | 512 | return _nums[index] + |
99 | 512 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - |
100 | 512 | static_cast<double>(_nums[index])); |
101 | 985 | } else { |
102 | 120 | DCHECK(_nums.empty()); |
103 | 120 | size_t rows = 0; |
104 | 260 | for (const auto& i : _sorted_nums_vec) { |
105 | 260 | rows += i.size(); |
106 | 260 | } |
107 | 120 | const bool reverse = quantile > 0.5 && rows > 2; |
108 | 120 | double u = (rows - 1) * quantile; |
109 | 120 | auto index = static_cast<uint32_t>(u); |
110 | | // if reverse, the step of target should start 0 like not reverse |
111 | | // so here rows need to minus index + 2 |
112 | | // eg: rows = 10, index = 5 |
113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 |
114 | | // if reverse, so the second number is 3, the first number is 4 |
115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. |
116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 |
117 | 120 | size_t target = reverse ? rows - index - 2 : index; |
118 | 120 | if (quantile == 1) { |
119 | 0 | target = 0; |
120 | 0 | } |
121 | 120 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); |
122 | 120 | if (quantile == 1) { |
123 | 0 | return second_number; |
124 | 0 | } |
125 | 120 | return first_number + |
126 | 120 | (u - static_cast<double>(index)) * |
127 | 120 | (static_cast<double>(second_number) - static_cast<double>(first_number)); |
128 | 120 | } |
129 | 1.10k | } _ZN5doris6CountsIaE9terminateEd Line | Count | Source | 76 | 61 | double terminate(double quantile) { | 77 | 61 | if (_sorted_nums_vec.size() <= 1) { | 78 | 58 | if (_sorted_nums_vec.size() == 1) { | 79 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 80 | 0 | } | 81 | | | 82 | 58 | if (_nums.empty()) { | 83 | | // Although set null here, but the value is 0.0 and the call method just | 84 | | // get val in aggregate_function_percentile_approx.h | 85 | 0 | return 0.0; | 86 | 0 | } | 87 | | | 88 | 58 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 89 | 24 | pdqsort(_nums.begin(), _nums.end()); | 90 | 24 | } | 91 | | | 92 | 58 | if (quantile == 1 || _nums.size() == 1) { | 93 | 34 | return _nums.back(); | 94 | 34 | } | 95 | | | 96 | 24 | double u = (_nums.size() - 1) * quantile; | 97 | 24 | auto index = static_cast<uint32_t>(u); | 98 | 24 | return _nums[index] + | 99 | 24 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 100 | 24 | static_cast<double>(_nums[index])); | 101 | 58 | } else { | 102 | 3 | DCHECK(_nums.empty()); | 103 | 3 | size_t rows = 0; | 104 | 6 | for (const auto& i : _sorted_nums_vec) { | 105 | 6 | rows += i.size(); | 106 | 6 | } | 107 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 108 | 3 | double u = (rows - 1) * quantile; | 109 | 3 | auto index = static_cast<uint32_t>(u); | 110 | | // if reverse, the step of target should start 0 like not reverse | 111 | | // so here rows need to minus index + 2 | 112 | | // eg: rows = 10, index = 5 | 113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 114 | | // if reverse, so the second number is 3, the first number is 4 | 115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 117 | 3 | size_t target = reverse ? rows - index - 2 : index; | 118 | 3 | if (quantile == 1) { | 119 | 0 | target = 0; | 120 | 0 | } | 121 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 122 | 3 | if (quantile == 1) { | 123 | 0 | return second_number; | 124 | 0 | } | 125 | 3 | return first_number + | 126 | 3 | (u - static_cast<double>(index)) * | 127 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 128 | 3 | } | 129 | 61 | } |
_ZN5doris6CountsIsE9terminateEd Line | Count | Source | 76 | 300 | double terminate(double quantile) { | 77 | 300 | if (_sorted_nums_vec.size() <= 1) { | 78 | 294 | if (_sorted_nums_vec.size() == 1) { | 79 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 80 | 0 | } | 81 | | | 82 | 294 | if (_nums.empty()) { | 83 | | // Although set null here, but the value is 0.0 and the call method just | 84 | | // get val in aggregate_function_percentile_approx.h | 85 | 0 | return 0.0; | 86 | 0 | } | 87 | | | 88 | 294 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 89 | 144 | pdqsort(_nums.begin(), _nums.end()); | 90 | 144 | } | 91 | | | 92 | 294 | if (quantile == 1 || _nums.size() == 1) { | 93 | 87 | return _nums.back(); | 94 | 87 | } | 95 | | | 96 | 207 | double u = (_nums.size() - 1) * quantile; | 97 | 207 | auto index = static_cast<uint32_t>(u); | 98 | 207 | return _nums[index] + | 99 | 207 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 100 | 207 | static_cast<double>(_nums[index])); | 101 | 294 | } else { | 102 | 6 | DCHECK(_nums.empty()); | 103 | 6 | size_t rows = 0; | 104 | 18 | for (const auto& i : _sorted_nums_vec) { | 105 | 18 | rows += i.size(); | 106 | 18 | } | 107 | 6 | const bool reverse = quantile > 0.5 && rows > 2; | 108 | 6 | double u = (rows - 1) * quantile; | 109 | 6 | auto index = static_cast<uint32_t>(u); | 110 | | // if reverse, the step of target should start 0 like not reverse | 111 | | // so here rows need to minus index + 2 | 112 | | // eg: rows = 10, index = 5 | 113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 114 | | // if reverse, so the second number is 3, the first number is 4 | 115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 117 | 6 | size_t target = reverse ? rows - index - 2 : index; | 118 | 6 | if (quantile == 1) { | 119 | 0 | target = 0; | 120 | 0 | } | 121 | 6 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 122 | 6 | if (quantile == 1) { | 123 | 0 | return second_number; | 124 | 0 | } | 125 | 6 | return first_number + | 126 | 6 | (u - static_cast<double>(index)) * | 127 | 6 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 128 | 6 | } | 129 | 300 | } |
_ZN5doris6CountsIiE9terminateEd Line | Count | Source | 76 | 444 | double terminate(double quantile) { | 77 | 444 | if (_sorted_nums_vec.size() <= 1) { | 78 | 387 | if (_sorted_nums_vec.size() == 1) { | 79 | 269 | _nums = std::move(_sorted_nums_vec[0]); | 80 | 269 | } | 81 | | | 82 | 387 | if (_nums.empty()) { | 83 | | // Although set null here, but the value is 0.0 and the call method just | 84 | | // get val in aggregate_function_percentile_approx.h | 85 | 0 | return 0.0; | 86 | 0 | } | 87 | | | 88 | 387 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 89 | 11 | pdqsort(_nums.begin(), _nums.end()); | 90 | 11 | } | 91 | | | 92 | 387 | if (quantile == 1 || _nums.size() == 1) { | 93 | 239 | return _nums.back(); | 94 | 239 | } | 95 | | | 96 | 148 | double u = (_nums.size() - 1) * quantile; | 97 | 148 | auto index = static_cast<uint32_t>(u); | 98 | 148 | return _nums[index] + | 99 | 148 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 100 | 148 | static_cast<double>(_nums[index])); | 101 | 387 | } else { | 102 | 57 | DCHECK(_nums.empty()); | 103 | 57 | size_t rows = 0; | 104 | 114 | for (const auto& i : _sorted_nums_vec) { | 105 | 114 | rows += i.size(); | 106 | 114 | } | 107 | 57 | const bool reverse = quantile > 0.5 && rows > 2; | 108 | 57 | double u = (rows - 1) * quantile; | 109 | 57 | auto index = static_cast<uint32_t>(u); | 110 | | // if reverse, the step of target should start 0 like not reverse | 111 | | // so here rows need to minus index + 2 | 112 | | // eg: rows = 10, index = 5 | 113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 114 | | // if reverse, so the second number is 3, the first number is 4 | 115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 117 | 57 | size_t target = reverse ? rows - index - 2 : index; | 118 | 57 | if (quantile == 1) { | 119 | 0 | target = 0; | 120 | 0 | } | 121 | 57 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 122 | 57 | if (quantile == 1) { | 123 | 0 | return second_number; | 124 | 0 | } | 125 | 57 | return first_number + | 126 | 57 | (u - static_cast<double>(index)) * | 127 | 57 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 128 | 57 | } | 129 | 444 | } |
_ZN5doris6CountsIlE9terminateEd Line | Count | Source | 76 | 128 | double terminate(double quantile) { | 77 | 128 | if (_sorted_nums_vec.size() <= 1) { | 78 | 107 | if (_sorted_nums_vec.size() == 1) { | 79 | 37 | _nums = std::move(_sorted_nums_vec[0]); | 80 | 37 | } | 81 | | | 82 | 107 | if (_nums.empty()) { | 83 | | // Although set null here, but the value is 0.0 and the call method just | 84 | | // get val in aggregate_function_percentile_approx.h | 85 | 0 | return 0.0; | 86 | 0 | } | 87 | | | 88 | 107 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 89 | 1 | pdqsort(_nums.begin(), _nums.end()); | 90 | 1 | } | 91 | | | 92 | 107 | if (quantile == 1 || _nums.size() == 1) { | 93 | 59 | return _nums.back(); | 94 | 59 | } | 95 | | | 96 | 48 | double u = (_nums.size() - 1) * quantile; | 97 | 48 | auto index = static_cast<uint32_t>(u); | 98 | 48 | return _nums[index] + | 99 | 48 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 100 | 48 | static_cast<double>(_nums[index])); | 101 | 107 | } else { | 102 | 21 | DCHECK(_nums.empty()); | 103 | 21 | size_t rows = 0; | 104 | 56 | for (const auto& i : _sorted_nums_vec) { | 105 | 56 | rows += i.size(); | 106 | 56 | } | 107 | 21 | const bool reverse = quantile > 0.5 && rows > 2; | 108 | 21 | double u = (rows - 1) * quantile; | 109 | 21 | auto index = static_cast<uint32_t>(u); | 110 | | // if reverse, the step of target should start 0 like not reverse | 111 | | // so here rows need to minus index + 2 | 112 | | // eg: rows = 10, index = 5 | 113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 114 | | // if reverse, so the second number is 3, the first number is 4 | 115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 117 | 21 | size_t target = reverse ? rows - index - 2 : index; | 118 | 21 | if (quantile == 1) { | 119 | 0 | target = 0; | 120 | 0 | } | 121 | 21 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 122 | 21 | if (quantile == 1) { | 123 | 0 | return second_number; | 124 | 0 | } | 125 | 21 | return first_number + | 126 | 21 | (u - static_cast<double>(index)) * | 127 | 21 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 128 | 21 | } | 129 | 128 | } |
_ZN5doris6CountsInE9terminateEd Line | Count | Source | 76 | 33 | double terminate(double quantile) { | 77 | 33 | if (_sorted_nums_vec.size() <= 1) { | 78 | 30 | if (_sorted_nums_vec.size() == 1) { | 79 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 80 | 0 | } | 81 | | | 82 | 30 | if (_nums.empty()) { | 83 | | // Although set null here, but the value is 0.0 and the call method just | 84 | | // get val in aggregate_function_percentile_approx.h | 85 | 0 | return 0.0; | 86 | 0 | } | 87 | | | 88 | 30 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 89 | 0 | pdqsort(_nums.begin(), _nums.end()); | 90 | 0 | } | 91 | | | 92 | 30 | if (quantile == 1 || _nums.size() == 1) { | 93 | 24 | return _nums.back(); | 94 | 24 | } | 95 | | | 96 | 6 | double u = (_nums.size() - 1) * quantile; | 97 | 6 | auto index = static_cast<uint32_t>(u); | 98 | 6 | return _nums[index] + | 99 | 6 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 100 | 6 | static_cast<double>(_nums[index])); | 101 | 30 | } else { | 102 | 3 | DCHECK(_nums.empty()); | 103 | 3 | size_t rows = 0; | 104 | 6 | for (const auto& i : _sorted_nums_vec) { | 105 | 6 | rows += i.size(); | 106 | 6 | } | 107 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 108 | 3 | double u = (rows - 1) * quantile; | 109 | 3 | auto index = static_cast<uint32_t>(u); | 110 | | // if reverse, the step of target should start 0 like not reverse | 111 | | // so here rows need to minus index + 2 | 112 | | // eg: rows = 10, index = 5 | 113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 114 | | // if reverse, so the second number is 3, the first number is 4 | 115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 117 | 3 | size_t target = reverse ? rows - index - 2 : index; | 118 | 3 | if (quantile == 1) { | 119 | 0 | target = 0; | 120 | 0 | } | 121 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 122 | 3 | if (quantile == 1) { | 123 | 0 | return second_number; | 124 | 0 | } | 125 | 3 | return first_number + | 126 | 3 | (u - static_cast<double>(index)) * | 127 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 128 | 3 | } | 129 | 33 | } |
_ZN5doris6CountsIfE9terminateEd Line | Count | Source | 76 | 3 | double terminate(double quantile) { | 77 | 3 | if (_sorted_nums_vec.size() <= 1) { | 78 | 0 | if (_sorted_nums_vec.size() == 1) { | 79 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 80 | 0 | } | 81 | |
| 82 | 0 | if (_nums.empty()) { | 83 | | // Although set null here, but the value is 0.0 and the call method just | 84 | | // get val in aggregate_function_percentile_approx.h | 85 | 0 | return 0.0; | 86 | 0 | } | 87 | | | 88 | 0 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 89 | 0 | pdqsort(_nums.begin(), _nums.end()); | 90 | 0 | } | 91 | |
| 92 | 0 | if (quantile == 1 || _nums.size() == 1) { | 93 | 0 | return _nums.back(); | 94 | 0 | } | 95 | | | 96 | 0 | double u = (_nums.size() - 1) * quantile; | 97 | 0 | auto index = static_cast<uint32_t>(u); | 98 | 0 | return _nums[index] + | 99 | 0 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 100 | 0 | static_cast<double>(_nums[index])); | 101 | 3 | } else { | 102 | 3 | DCHECK(_nums.empty()); | 103 | 3 | size_t rows = 0; | 104 | 6 | for (const auto& i : _sorted_nums_vec) { | 105 | 6 | rows += i.size(); | 106 | 6 | } | 107 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 108 | 3 | double u = (rows - 1) * quantile; | 109 | 3 | auto index = static_cast<uint32_t>(u); | 110 | | // if reverse, the step of target should start 0 like not reverse | 111 | | // so here rows need to minus index + 2 | 112 | | // eg: rows = 10, index = 5 | 113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 114 | | // if reverse, so the second number is 3, the first number is 4 | 115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 117 | 3 | size_t target = reverse ? rows - index - 2 : index; | 118 | 3 | if (quantile == 1) { | 119 | 0 | target = 0; | 120 | 0 | } | 121 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 122 | 3 | if (quantile == 1) { | 123 | 0 | return second_number; | 124 | 0 | } | 125 | 3 | return first_number + | 126 | 3 | (u - static_cast<double>(index)) * | 127 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 128 | 3 | } | 129 | 3 | } |
_ZN5doris6CountsIdE9terminateEd Line | Count | Source | 76 | 136 | double terminate(double quantile) { | 77 | 136 | if (_sorted_nums_vec.size() <= 1) { | 78 | 109 | if (_sorted_nums_vec.size() == 1) { | 79 | 26 | _nums = std::move(_sorted_nums_vec[0]); | 80 | 26 | } | 81 | | | 82 | 109 | if (_nums.empty()) { | 83 | | // Although set null here, but the value is 0.0 and the call method just | 84 | | // get val in aggregate_function_percentile_approx.h | 85 | 0 | return 0.0; | 86 | 0 | } | 87 | | | 88 | 109 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 89 | 0 | pdqsort(_nums.begin(), _nums.end()); | 90 | 0 | } | 91 | | | 92 | 109 | if (quantile == 1 || _nums.size() == 1) { | 93 | 30 | return _nums.back(); | 94 | 30 | } | 95 | | | 96 | 79 | double u = (_nums.size() - 1) * quantile; | 97 | 79 | auto index = static_cast<uint32_t>(u); | 98 | 79 | return _nums[index] + | 99 | 79 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 100 | 79 | static_cast<double>(_nums[index])); | 101 | 109 | } else { | 102 | 27 | DCHECK(_nums.empty()); | 103 | 27 | size_t rows = 0; | 104 | 54 | for (const auto& i : _sorted_nums_vec) { | 105 | 54 | rows += i.size(); | 106 | 54 | } | 107 | 27 | const bool reverse = quantile > 0.5 && rows > 2; | 108 | 27 | double u = (rows - 1) * quantile; | 109 | 27 | auto index = static_cast<uint32_t>(u); | 110 | | // if reverse, the step of target should start 0 like not reverse | 111 | | // so here rows need to minus index + 2 | 112 | | // eg: rows = 10, index = 5 | 113 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 114 | | // if reverse, so the second number is 3, the first number is 4 | 115 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 116 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 117 | 27 | size_t target = reverse ? rows - index - 2 : index; | 118 | 27 | if (quantile == 1) { | 119 | 0 | target = 0; | 120 | 0 | } | 121 | 27 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 122 | 27 | if (quantile == 1) { | 123 | 0 | return second_number; | 124 | 0 | } | 125 | 27 | return first_number + | 126 | 27 | (u - static_cast<double>(index)) * | 127 | 27 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 128 | 27 | } | 129 | 136 | } |
|
130 | | |
131 | | private: |
132 | | struct Node { |
133 | | Ty value; |
134 | | int array_index; |
135 | | int64_t element_index; |
136 | | |
137 | 988 | auto operator<=>(const Node& other) const { return value <=> other.value; }_ZNK5doris6CountsIaE4NodessERKS2_ Line | Count | Source | 137 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIsE4NodessERKS2_ Line | Count | Source | 137 | 74 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIiE4NodessERKS2_ Line | Count | Source | 137 | 487 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIlE4NodessERKS2_ Line | Count | Source | 137 | 360 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsInE4NodessERKS2_ Line | Count | Source | 137 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIfE4NodessERKS2_ Line | Count | Source | 137 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIdE4NodessERKS2_ Line | Count | Source | 137 | 49 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
|
138 | | }; |
139 | | |
140 | 298 | void _convert_sorted_num_vec_to_nums() { |
141 | 298 | size_t rows = 0; |
142 | 596 | for (const auto& i : _sorted_nums_vec) { |
143 | 596 | rows += i.size(); |
144 | 596 | } |
145 | 298 | _nums.resize(rows); |
146 | 298 | size_t count = 0; |
147 | | |
148 | 298 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
149 | 894 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
150 | 596 | if (!_sorted_nums_vec[i].empty()) { |
151 | 596 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
152 | 596 | } |
153 | 596 | } |
154 | | |
155 | 1.04k | while (!min_heap.empty()) { |
156 | 743 | Node node = min_heap.top(); |
157 | 743 | min_heap.pop(); |
158 | 743 | _nums[count++] = node.value; |
159 | 743 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
160 | 147 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
161 | 147 | min_heap.push(node); |
162 | 147 | } |
163 | 743 | } |
164 | 298 | _sorted_nums_vec.clear(); |
165 | 298 | } Unexecuted instantiation: _ZN5doris6CountsIaE31_convert_sorted_num_vec_to_numsEv Unexecuted instantiation: _ZN5doris6CountsIsE31_convert_sorted_num_vec_to_numsEv _ZN5doris6CountsIiE31_convert_sorted_num_vec_to_numsEv Line | Count | Source | 140 | 156 | void _convert_sorted_num_vec_to_nums() { | 141 | 156 | size_t rows = 0; | 142 | 339 | for (const auto& i : _sorted_nums_vec) { | 143 | 339 | rows += i.size(); | 144 | 339 | } | 145 | 156 | _nums.resize(rows); | 146 | 156 | size_t count = 0; | 147 | | | 148 | 156 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 149 | 495 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 150 | 339 | if (!_sorted_nums_vec[i].empty()) { | 151 | 339 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 152 | 339 | } | 153 | 339 | } | 154 | | | 155 | 531 | while (!min_heap.empty()) { | 156 | 375 | Node node = min_heap.top(); | 157 | 375 | min_heap.pop(); | 158 | 375 | _nums[count++] = node.value; | 159 | 375 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 160 | 36 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 161 | 36 | min_heap.push(node); | 162 | 36 | } | 163 | 375 | } | 164 | 156 | _sorted_nums_vec.clear(); | 165 | 156 | } |
_ZN5doris6CountsIlE31_convert_sorted_num_vec_to_numsEv Line | Count | Source | 140 | 142 | void _convert_sorted_num_vec_to_nums() { | 141 | 142 | size_t rows = 0; | 142 | 257 | for (const auto& i : _sorted_nums_vec) { | 143 | 257 | rows += i.size(); | 144 | 257 | } | 145 | 142 | _nums.resize(rows); | 146 | 142 | size_t count = 0; | 147 | | | 148 | 142 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 149 | 399 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 150 | 257 | if (!_sorted_nums_vec[i].empty()) { | 151 | 257 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 152 | 257 | } | 153 | 257 | } | 154 | | | 155 | 510 | while (!min_heap.empty()) { | 156 | 368 | Node node = min_heap.top(); | 157 | 368 | min_heap.pop(); | 158 | 368 | _nums[count++] = node.value; | 159 | 368 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 160 | 111 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 161 | 111 | min_heap.push(node); | 162 | 111 | } | 163 | 368 | } | 164 | 142 | _sorted_nums_vec.clear(); | 165 | 142 | } |
Unexecuted instantiation: _ZN5doris6CountsInE31_convert_sorted_num_vec_to_numsEv Unexecuted instantiation: _ZN5doris6CountsIfE31_convert_sorted_num_vec_to_numsEv Unexecuted instantiation: _ZN5doris6CountsIdE31_convert_sorted_num_vec_to_numsEv |
166 | | |
167 | 120 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { |
168 | 120 | Ty first_number = 0, second_number = 0; |
169 | 120 | size_t count = 0; |
170 | 120 | if (reverse) { |
171 | 31 | std::priority_queue<Node> max_heap; |
172 | 109 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
173 | 78 | if (!_sorted_nums_vec[i].empty()) { |
174 | 78 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, |
175 | 78 | _sorted_nums_vec[i].size() - 1); |
176 | 78 | } |
177 | 78 | } |
178 | | |
179 | 118 | while (!max_heap.empty()) { |
180 | 118 | Node node = max_heap.top(); |
181 | 118 | max_heap.pop(); |
182 | 118 | if (count == target) { |
183 | 31 | second_number = node.value; |
184 | 87 | } else if (count == target + 1) { |
185 | 31 | first_number = node.value; |
186 | 31 | break; |
187 | 31 | } |
188 | 87 | ++count; |
189 | 87 | if (--node.element_index >= 0) { |
190 | 78 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
191 | 78 | max_heap.push(node); |
192 | 78 | } |
193 | 87 | } |
194 | | |
195 | 89 | } else { |
196 | 89 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
197 | 271 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
198 | 182 | if (!_sorted_nums_vec[i].empty()) { |
199 | 182 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
200 | 182 | } |
201 | 182 | } |
202 | | |
203 | 285 | while (!min_heap.empty()) { |
204 | 285 | Node node = min_heap.top(); |
205 | 285 | min_heap.pop(); |
206 | 285 | if (count == target) { |
207 | 89 | first_number = node.value; |
208 | 196 | } else if (count == target + 1) { |
209 | 89 | second_number = node.value; |
210 | 89 | break; |
211 | 89 | } |
212 | 196 | ++count; |
213 | 196 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
214 | 168 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
215 | 168 | min_heap.push(node); |
216 | 168 | } |
217 | 196 | } |
218 | 89 | } |
219 | | |
220 | 120 | return {first_number, second_number}; |
221 | 120 | } _ZN5doris6CountsIaE27_merge_sort_and_get_numbersElb Line | Count | Source | 167 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 168 | 3 | Ty first_number = 0, second_number = 0; | 169 | 3 | size_t count = 0; | 170 | 3 | if (reverse) { | 171 | 1 | std::priority_queue<Node> max_heap; | 172 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 173 | 2 | if (!_sorted_nums_vec[i].empty()) { | 174 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 175 | 2 | _sorted_nums_vec[i].size() - 1); | 176 | 2 | } | 177 | 2 | } | 178 | | | 179 | 2 | while (!max_heap.empty()) { | 180 | 2 | Node node = max_heap.top(); | 181 | 2 | max_heap.pop(); | 182 | 2 | if (count == target) { | 183 | 1 | second_number = node.value; | 184 | 1 | } else if (count == target + 1) { | 185 | 1 | first_number = node.value; | 186 | 1 | break; | 187 | 1 | } | 188 | 1 | ++count; | 189 | 1 | if (--node.element_index >= 0) { | 190 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 191 | 1 | max_heap.push(node); | 192 | 1 | } | 193 | 1 | } | 194 | | | 195 | 2 | } else { | 196 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 197 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 198 | 4 | if (!_sorted_nums_vec[i].empty()) { | 199 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 200 | 4 | } | 201 | 4 | } | 202 | | | 203 | 6 | while (!min_heap.empty()) { | 204 | 6 | Node node = min_heap.top(); | 205 | 6 | min_heap.pop(); | 206 | 6 | if (count == target) { | 207 | 2 | first_number = node.value; | 208 | 4 | } else if (count == target + 1) { | 209 | 2 | second_number = node.value; | 210 | 2 | break; | 211 | 2 | } | 212 | 4 | ++count; | 213 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 214 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 215 | 2 | min_heap.push(node); | 216 | 2 | } | 217 | 4 | } | 218 | 2 | } | 219 | | | 220 | 3 | return {first_number, second_number}; | 221 | 3 | } |
_ZN5doris6CountsIsE27_merge_sort_and_get_numbersElb Line | Count | Source | 167 | 6 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 168 | 6 | Ty first_number = 0, second_number = 0; | 169 | 6 | size_t count = 0; | 170 | 6 | if (reverse) { | 171 | 2 | std::priority_queue<Node> max_heap; | 172 | 8 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 173 | 6 | if (!_sorted_nums_vec[i].empty()) { | 174 | 6 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 175 | 6 | _sorted_nums_vec[i].size() - 1); | 176 | 6 | } | 177 | 6 | } | 178 | | | 179 | 8 | while (!max_heap.empty()) { | 180 | 8 | Node node = max_heap.top(); | 181 | 8 | max_heap.pop(); | 182 | 8 | if (count == target) { | 183 | 2 | second_number = node.value; | 184 | 6 | } else if (count == target + 1) { | 185 | 2 | first_number = node.value; | 186 | 2 | break; | 187 | 2 | } | 188 | 6 | ++count; | 189 | 6 | if (--node.element_index >= 0) { | 190 | 4 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 191 | 4 | max_heap.push(node); | 192 | 4 | } | 193 | 6 | } | 194 | | | 195 | 4 | } else { | 196 | 4 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 197 | 16 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 198 | 12 | if (!_sorted_nums_vec[i].empty()) { | 199 | 12 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 200 | 12 | } | 201 | 12 | } | 202 | | | 203 | 19 | while (!min_heap.empty()) { | 204 | 19 | Node node = min_heap.top(); | 205 | 19 | min_heap.pop(); | 206 | 19 | if (count == target) { | 207 | 4 | first_number = node.value; | 208 | 15 | } else if (count == target + 1) { | 209 | 4 | second_number = node.value; | 210 | 4 | break; | 211 | 4 | } | 212 | 15 | ++count; | 213 | 15 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 214 | 13 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 215 | 13 | min_heap.push(node); | 216 | 13 | } | 217 | 15 | } | 218 | 4 | } | 219 | | | 220 | 6 | return {first_number, second_number}; | 221 | 6 | } |
_ZN5doris6CountsIiE27_merge_sort_and_get_numbersElb Line | Count | Source | 167 | 57 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 168 | 57 | Ty first_number = 0, second_number = 0; | 169 | 57 | size_t count = 0; | 170 | 57 | if (reverse) { | 171 | 9 | std::priority_queue<Node> max_heap; | 172 | 27 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 173 | 18 | if (!_sorted_nums_vec[i].empty()) { | 174 | 18 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 175 | 18 | _sorted_nums_vec[i].size() - 1); | 176 | 18 | } | 177 | 18 | } | 178 | | | 179 | 37 | while (!max_heap.empty()) { | 180 | 37 | Node node = max_heap.top(); | 181 | 37 | max_heap.pop(); | 182 | 37 | if (count == target) { | 183 | 9 | second_number = node.value; | 184 | 28 | } else if (count == target + 1) { | 185 | 9 | first_number = node.value; | 186 | 9 | break; | 187 | 9 | } | 188 | 28 | ++count; | 189 | 28 | if (--node.element_index >= 0) { | 190 | 24 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 191 | 24 | max_heap.push(node); | 192 | 24 | } | 193 | 28 | } | 194 | | | 195 | 48 | } else { | 196 | 48 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 197 | 144 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 198 | 96 | if (!_sorted_nums_vec[i].empty()) { | 199 | 96 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 200 | 96 | } | 201 | 96 | } | 202 | | | 203 | 166 | while (!min_heap.empty()) { | 204 | 166 | Node node = min_heap.top(); | 205 | 166 | min_heap.pop(); | 206 | 166 | if (count == target) { | 207 | 48 | first_number = node.value; | 208 | 118 | } else if (count == target + 1) { | 209 | 48 | second_number = node.value; | 210 | 48 | break; | 211 | 48 | } | 212 | 118 | ++count; | 213 | 118 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 214 | 115 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 215 | 115 | min_heap.push(node); | 216 | 115 | } | 217 | 118 | } | 218 | 48 | } | 219 | | | 220 | 57 | return {first_number, second_number}; | 221 | 57 | } |
_ZN5doris6CountsIlE27_merge_sort_and_get_numbersElb Line | Count | Source | 167 | 21 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 168 | 21 | Ty first_number = 0, second_number = 0; | 169 | 21 | size_t count = 0; | 170 | 21 | if (reverse) { | 171 | 14 | std::priority_queue<Node> max_heap; | 172 | 56 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 173 | 42 | if (!_sorted_nums_vec[i].empty()) { | 174 | 42 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 175 | 42 | _sorted_nums_vec[i].size() - 1); | 176 | 42 | } | 177 | 42 | } | 178 | | | 179 | 60 | while (!max_heap.empty()) { | 180 | 60 | Node node = max_heap.top(); | 181 | 60 | max_heap.pop(); | 182 | 60 | if (count == target) { | 183 | 14 | second_number = node.value; | 184 | 46 | } else if (count == target + 1) { | 185 | 14 | first_number = node.value; | 186 | 14 | break; | 187 | 14 | } | 188 | 46 | ++count; | 189 | 46 | if (--node.element_index >= 0) { | 190 | 44 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 191 | 44 | max_heap.push(node); | 192 | 44 | } | 193 | 46 | } | 194 | | | 195 | 14 | } else { | 196 | 7 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 197 | 21 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 198 | 14 | if (!_sorted_nums_vec[i].empty()) { | 199 | 14 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 200 | 14 | } | 201 | 14 | } | 202 | | | 203 | 24 | while (!min_heap.empty()) { | 204 | 24 | Node node = min_heap.top(); | 205 | 24 | min_heap.pop(); | 206 | 24 | if (count == target) { | 207 | 7 | first_number = node.value; | 208 | 17 | } else if (count == target + 1) { | 209 | 7 | second_number = node.value; | 210 | 7 | break; | 211 | 7 | } | 212 | 17 | ++count; | 213 | 17 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 214 | 15 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 215 | 15 | min_heap.push(node); | 216 | 15 | } | 217 | 17 | } | 218 | 7 | } | 219 | | | 220 | 21 | return {first_number, second_number}; | 221 | 21 | } |
_ZN5doris6CountsInE27_merge_sort_and_get_numbersElb Line | Count | Source | 167 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 168 | 3 | Ty first_number = 0, second_number = 0; | 169 | 3 | size_t count = 0; | 170 | 3 | if (reverse) { | 171 | 1 | std::priority_queue<Node> max_heap; | 172 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 173 | 2 | if (!_sorted_nums_vec[i].empty()) { | 174 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 175 | 2 | _sorted_nums_vec[i].size() - 1); | 176 | 2 | } | 177 | 2 | } | 178 | | | 179 | 2 | while (!max_heap.empty()) { | 180 | 2 | Node node = max_heap.top(); | 181 | 2 | max_heap.pop(); | 182 | 2 | if (count == target) { | 183 | 1 | second_number = node.value; | 184 | 1 | } else if (count == target + 1) { | 185 | 1 | first_number = node.value; | 186 | 1 | break; | 187 | 1 | } | 188 | 1 | ++count; | 189 | 1 | if (--node.element_index >= 0) { | 190 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 191 | 1 | max_heap.push(node); | 192 | 1 | } | 193 | 1 | } | 194 | | | 195 | 2 | } else { | 196 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 197 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 198 | 4 | if (!_sorted_nums_vec[i].empty()) { | 199 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 200 | 4 | } | 201 | 4 | } | 202 | | | 203 | 6 | while (!min_heap.empty()) { | 204 | 6 | Node node = min_heap.top(); | 205 | 6 | min_heap.pop(); | 206 | 6 | if (count == target) { | 207 | 2 | first_number = node.value; | 208 | 4 | } else if (count == target + 1) { | 209 | 2 | second_number = node.value; | 210 | 2 | break; | 211 | 2 | } | 212 | 4 | ++count; | 213 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 214 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 215 | 2 | min_heap.push(node); | 216 | 2 | } | 217 | 4 | } | 218 | 2 | } | 219 | | | 220 | 3 | return {first_number, second_number}; | 221 | 3 | } |
_ZN5doris6CountsIfE27_merge_sort_and_get_numbersElb Line | Count | Source | 167 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 168 | 3 | Ty first_number = 0, second_number = 0; | 169 | 3 | size_t count = 0; | 170 | 3 | if (reverse) { | 171 | 1 | std::priority_queue<Node> max_heap; | 172 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 173 | 2 | if (!_sorted_nums_vec[i].empty()) { | 174 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 175 | 2 | _sorted_nums_vec[i].size() - 1); | 176 | 2 | } | 177 | 2 | } | 178 | | | 179 | 2 | while (!max_heap.empty()) { | 180 | 2 | Node node = max_heap.top(); | 181 | 2 | max_heap.pop(); | 182 | 2 | if (count == target) { | 183 | 1 | second_number = node.value; | 184 | 1 | } else if (count == target + 1) { | 185 | 1 | first_number = node.value; | 186 | 1 | break; | 187 | 1 | } | 188 | 1 | ++count; | 189 | 1 | if (--node.element_index >= 0) { | 190 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 191 | 1 | max_heap.push(node); | 192 | 1 | } | 193 | 1 | } | 194 | | | 195 | 2 | } else { | 196 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 197 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 198 | 4 | if (!_sorted_nums_vec[i].empty()) { | 199 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 200 | 4 | } | 201 | 4 | } | 202 | | | 203 | 6 | while (!min_heap.empty()) { | 204 | 6 | Node node = min_heap.top(); | 205 | 6 | min_heap.pop(); | 206 | 6 | if (count == target) { | 207 | 2 | first_number = node.value; | 208 | 4 | } else if (count == target + 1) { | 209 | 2 | second_number = node.value; | 210 | 2 | break; | 211 | 2 | } | 212 | 4 | ++count; | 213 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 214 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 215 | 2 | min_heap.push(node); | 216 | 2 | } | 217 | 4 | } | 218 | 2 | } | 219 | | | 220 | 3 | return {first_number, second_number}; | 221 | 3 | } |
_ZN5doris6CountsIdE27_merge_sort_and_get_numbersElb Line | Count | Source | 167 | 27 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 168 | 27 | Ty first_number = 0, second_number = 0; | 169 | 27 | size_t count = 0; | 170 | 27 | if (reverse) { | 171 | 3 | std::priority_queue<Node> max_heap; | 172 | 9 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 173 | 6 | if (!_sorted_nums_vec[i].empty()) { | 174 | 6 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 175 | 6 | _sorted_nums_vec[i].size() - 1); | 176 | 6 | } | 177 | 6 | } | 178 | | | 179 | 7 | while (!max_heap.empty()) { | 180 | 7 | Node node = max_heap.top(); | 181 | 7 | max_heap.pop(); | 182 | 7 | if (count == target) { | 183 | 3 | second_number = node.value; | 184 | 4 | } else if (count == target + 1) { | 185 | 3 | first_number = node.value; | 186 | 3 | break; | 187 | 3 | } | 188 | 4 | ++count; | 189 | 4 | if (--node.element_index >= 0) { | 190 | 3 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 191 | 3 | max_heap.push(node); | 192 | 3 | } | 193 | 4 | } | 194 | | | 195 | 24 | } else { | 196 | 24 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 197 | 72 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 198 | 48 | if (!_sorted_nums_vec[i].empty()) { | 199 | 48 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 200 | 48 | } | 201 | 48 | } | 202 | | | 203 | 58 | while (!min_heap.empty()) { | 204 | 58 | Node node = min_heap.top(); | 205 | 58 | min_heap.pop(); | 206 | 58 | if (count == target) { | 207 | 24 | first_number = node.value; | 208 | 34 | } else if (count == target + 1) { | 209 | 24 | second_number = node.value; | 210 | 24 | break; | 211 | 24 | } | 212 | 34 | ++count; | 213 | 34 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 214 | 19 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 215 | 19 | min_heap.push(node); | 216 | 19 | } | 217 | 34 | } | 218 | 24 | } | 219 | | | 220 | 27 | return {first_number, second_number}; | 221 | 27 | } |
|
222 | | |
223 | | PODArray<Ty> _nums; |
224 | | std::vector<PODArray<Ty>> _sorted_nums_vec; |
225 | | }; |
226 | | |
227 | | } // namespace doris |