/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 "vec/common/pod_array.h" |
27 | | #include "vec/common/string_buffer.hpp" |
28 | | #include "vec/io/io_helper.h" |
29 | | |
30 | | namespace doris { |
31 | | |
32 | | template <typename Ty> |
33 | | class Counts { |
34 | | public: |
35 | | Counts() = default; |
36 | 3.59k | |
37 | | void merge(Counts* other) { |
38 | 1.27k | if (other != nullptr && !other->_nums.empty()) { |
39 | 1.27k | _sorted_nums_vec.emplace_back(std::move(other->_nums)); |
40 | 1.27k | } |
41 | 1.27k | } |
42 | 1.27k | _ZN5doris6CountsIaE5mergeEPS1_ Line | Count | Source | 38 | 5 | if (other != nullptr && !other->_nums.empty()) { | 39 | 5 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 5 | } | 41 | 5 | } | 42 | 5 | |
_ZN5doris6CountsIsE5mergeEPS1_ Line | Count | Source | 38 | 14 | if (other != nullptr && !other->_nums.empty()) { | 39 | 14 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 14 | } | 41 | 14 | } | 42 | 14 | |
_ZN5doris6CountsIiE5mergeEPS1_ Line | Count | Source | 38 | 837 | if (other != nullptr && !other->_nums.empty()) { | 39 | 837 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 837 | } | 41 | 837 | } | 42 | 837 | |
_ZN5doris6CountsIlE5mergeEPS1_ Line | Count | Source | 38 | 315 | if (other != nullptr && !other->_nums.empty()) { | 39 | 315 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 315 | } | 41 | 315 | } | 42 | 315 | |
_ZN5doris6CountsInE5mergeEPS1_ Line | Count | Source | 38 | 5 | if (other != nullptr && !other->_nums.empty()) { | 39 | 5 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 5 | } | 41 | 5 | } | 42 | 5 | |
_ZN5doris6CountsIfE5mergeEPS1_ Line | Count | Source | 38 | 5 | if (other != nullptr && !other->_nums.empty()) { | 39 | 5 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 5 | } | 41 | 5 | } | 42 | 5 | |
_ZN5doris6CountsIdE5mergeEPS1_ Line | Count | Source | 38 | 91 | if (other != nullptr && !other->_nums.empty()) { | 39 | 91 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 91 | } | 41 | 91 | } | 42 | 91 | |
|
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 | | void increment(Ty key) { _nums.push_back(key); } |
52 | 2.93k | _ZN5doris6CountsIaE9incrementEa Line | Count | Source | 52 | 73 | |
_ZN5doris6CountsIsE9incrementEs Line | Count | Source | 52 | 552 | |
_ZN5doris6CountsIiE9incrementEi Line | Count | Source | 52 | 1.59k | |
_ZN5doris6CountsIlE9incrementEl Line | Count | Source | 52 | 401 | |
_ZN5doris6CountsInE9incrementEn Line | Count | Source | 52 | 45 | |
_ZN5doris6CountsIfE9incrementEf Line | Count | Source | 52 | 9 | |
_ZN5doris6CountsIdE9incrementEd Line | Count | Source | 52 | 259 | |
|
53 | | void increment_batch(const vectorized::PaddedPODArray<Ty>& keys) { |
54 | 5 | _nums.insert(keys.begin(), keys.end()); |
55 | 5 | } |
56 | 5 | Unexecuted instantiation: _ZN5doris6CountsIaE15increment_batchERKNS_10vectorized8PODArrayIaLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIsE15increment_batchERKNS_10vectorized8PODArrayIsLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIiE15increment_batchERKNS_10vectorized8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE _ZN5doris6CountsIlE15increment_batchERKNS_10vectorized8PODArrayIlLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Line | Count | Source | 54 | 5 | _nums.insert(keys.begin(), keys.end()); | 55 | 5 | } | 56 | 5 | |
Unexecuted instantiation: _ZN5doris6CountsInE15increment_batchERKNS_10vectorized8PODArrayInLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIfE15increment_batchERKNS_10vectorized8PODArrayIfLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIdE15increment_batchERKNS_10vectorized8PODArrayIdLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE |
57 | | void serialize(vectorized::BufferWritable& buf) { |
58 | 1.66k | if (!_nums.empty()) { |
59 | 1.66k | pdqsort(_nums.begin(), _nums.end()); |
60 | 1.39k | size_t size = _nums.size(); |
61 | 1.39k | buf.write_binary(size); |
62 | 1.39k | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); |
63 | 1.39k | } else { |
64 | 1.39k | // convert _sorted_nums_vec to _nums and do seiralize again |
65 | | _convert_sorted_num_vec_to_nums(); |
66 | 265 | serialize(buf); |
67 | 265 | } |
68 | 265 | } |
69 | 1.66k | _ZN5doris6CountsIaE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 58 | 5 | if (!_nums.empty()) { | 59 | 5 | pdqsort(_nums.begin(), _nums.end()); | 60 | 5 | size_t size = _nums.size(); | 61 | 5 | buf.write_binary(size); | 62 | 5 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 5 | } else { | 64 | 5 | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 0 | } | 69 | 5 | |
_ZN5doris6CountsIsE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 58 | 14 | if (!_nums.empty()) { | 59 | 14 | pdqsort(_nums.begin(), _nums.end()); | 60 | 14 | size_t size = _nums.size(); | 61 | 14 | buf.write_binary(size); | 62 | 14 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 14 | } else { | 64 | 14 | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 0 | } | 69 | 14 | |
_ZN5doris6CountsIiE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 58 | 1.11k | if (!_nums.empty()) { | 59 | 1.11k | pdqsort(_nums.begin(), _nums.end()); | 60 | 954 | size_t size = _nums.size(); | 61 | 954 | buf.write_binary(size); | 62 | 954 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 954 | } else { | 64 | 954 | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | | _convert_sorted_num_vec_to_nums(); | 66 | 156 | serialize(buf); | 67 | 156 | } | 68 | 156 | } | 69 | 1.11k | |
_ZN5doris6CountsIlE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 58 | 433 | if (!_nums.empty()) { | 59 | 433 | pdqsort(_nums.begin(), _nums.end()); | 60 | 324 | size_t size = _nums.size(); | 61 | 324 | buf.write_binary(size); | 62 | 324 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 324 | } else { | 64 | 324 | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | | _convert_sorted_num_vec_to_nums(); | 66 | 109 | serialize(buf); | 67 | 109 | } | 68 | 109 | } | 69 | 433 | |
_ZN5doris6CountsInE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 58 | 5 | if (!_nums.empty()) { | 59 | 5 | pdqsort(_nums.begin(), _nums.end()); | 60 | 5 | size_t size = _nums.size(); | 61 | 5 | buf.write_binary(size); | 62 | 5 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 5 | } else { | 64 | 5 | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 0 | } | 69 | 5 | |
_ZN5doris6CountsIfE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 58 | 5 | if (!_nums.empty()) { | 59 | 5 | pdqsort(_nums.begin(), _nums.end()); | 60 | 5 | size_t size = _nums.size(); | 61 | 5 | buf.write_binary(size); | 62 | 5 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 5 | } else { | 64 | 5 | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 0 | } | 69 | 5 | |
_ZN5doris6CountsIdE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 58 | 91 | if (!_nums.empty()) { | 59 | 91 | pdqsort(_nums.begin(), _nums.end()); | 60 | 91 | size_t size = _nums.size(); | 61 | 91 | buf.write_binary(size); | 62 | 91 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 91 | } else { | 64 | 91 | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 0 | } | 69 | 91 | |
|
70 | | void unserialize(vectorized::BufferReadable& buf) { |
71 | 1.27k | size_t size; |
72 | 1.27k | buf.read_binary(size); |
73 | 1.27k | _nums.resize(size); |
74 | 1.27k | auto buff = buf.read(sizeof(Ty) * size); |
75 | 1.27k | memcpy(_nums.data(), buff.data, buff.size); |
76 | 1.27k | } |
77 | 1.27k | _ZN5doris6CountsIaE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 71 | 5 | size_t size; | 72 | 5 | buf.read_binary(size); | 73 | 5 | _nums.resize(size); | 74 | 5 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 5 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 5 | } | 77 | 5 | |
_ZN5doris6CountsIsE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 71 | 14 | size_t size; | 72 | 14 | buf.read_binary(size); | 73 | 14 | _nums.resize(size); | 74 | 14 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 14 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 14 | } | 77 | 14 | |
_ZN5doris6CountsIiE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 71 | 836 | size_t size; | 72 | 836 | buf.read_binary(size); | 73 | 836 | _nums.resize(size); | 74 | 836 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 836 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 836 | } | 77 | 836 | |
_ZN5doris6CountsIlE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 71 | 315 | size_t size; | 72 | 315 | buf.read_binary(size); | 73 | 315 | _nums.resize(size); | 74 | 315 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 315 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 315 | } | 77 | 315 | |
_ZN5doris6CountsInE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 71 | 5 | size_t size; | 72 | 5 | buf.read_binary(size); | 73 | 5 | _nums.resize(size); | 74 | 5 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 5 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 5 | } | 77 | 5 | |
_ZN5doris6CountsIfE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 71 | 5 | size_t size; | 72 | 5 | buf.read_binary(size); | 73 | 5 | _nums.resize(size); | 74 | 5 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 5 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 5 | } | 77 | 5 | |
_ZN5doris6CountsIdE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 71 | 91 | size_t size; | 72 | 91 | buf.read_binary(size); | 73 | 91 | _nums.resize(size); | 74 | 91 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 91 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 91 | } | 77 | 91 | |
|
78 | | double terminate(double quantile) { |
79 | 1.10k | if (_sorted_nums_vec.size() <= 1) { |
80 | 1.10k | if (_sorted_nums_vec.size() == 1) { |
81 | 945 | _nums = std::move(_sorted_nums_vec[0]); |
82 | 292 | } |
83 | 292 | |
84 | | if (_nums.empty()) { |
85 | 945 | // Although set null here, but the value is 0.0 and the call method just |
86 | | // get val in aggregate_function_percentile_approx.h |
87 | | return 0.0; |
88 | 0 | } |
89 | 0 | |
90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { |
91 | 945 | pdqsort(_nums.begin(), _nums.end()); |
92 | 180 | } |
93 | 180 | |
94 | | if (quantile == 1 || _nums.size() == 1) { |
95 | 945 | return _nums.back(); |
96 | 473 | } |
97 | 473 | |
98 | | double u = (_nums.size() - 1) * quantile; |
99 | 472 | auto index = static_cast<uint32_t>(u); |
100 | 472 | return _nums[index] + |
101 | 472 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - |
102 | 472 | static_cast<double>(_nums[index])); |
103 | 472 | } else { |
104 | 945 | DCHECK(_nums.empty()); |
105 | 160 | size_t rows = 0; |
106 | 160 | for (const auto& i : _sorted_nums_vec) { |
107 | 422 | rows += i.size(); |
108 | 422 | } |
109 | 422 | const bool reverse = quantile > 0.5 && rows > 2; |
110 | 160 | double u = (rows - 1) * quantile; |
111 | 160 | auto index = static_cast<uint32_t>(u); |
112 | 160 | // if reverse, the step of target should start 0 like not reverse |
113 | | // so here rows need to minus index + 2 |
114 | | // eg: rows = 10, index = 5 |
115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 |
116 | | // if reverse, so the second number is 3, the first number is 4 |
117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. |
118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 |
119 | | size_t target = reverse ? rows - index - 2 : index; |
120 | 160 | if (quantile == 1) { |
121 | 160 | target = 0; |
122 | 0 | } |
123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); |
124 | 160 | if (quantile == 1) { |
125 | 160 | return second_number; |
126 | 0 | } |
127 | 0 | return first_number + |
128 | 160 | (u - static_cast<double>(index)) * |
129 | 160 | (static_cast<double>(second_number) - static_cast<double>(first_number)); |
130 | 160 | } |
131 | 160 | } |
132 | 1.10k | _ZN5doris6CountsIaE9terminateEd Line | Count | Source | 79 | 61 | if (_sorted_nums_vec.size() <= 1) { | 80 | 61 | if (_sorted_nums_vec.size() == 1) { | 81 | 59 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 1 | } | 83 | 1 | | 84 | | if (_nums.empty()) { | 85 | 59 | // Although set null here, but the value is 0.0 and the call method just | 86 | | // get val in aggregate_function_percentile_approx.h | 87 | | return 0.0; | 88 | 0 | } | 89 | 0 | | 90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 59 | pdqsort(_nums.begin(), _nums.end()); | 92 | 24 | } | 93 | 24 | | 94 | | if (quantile == 1 || _nums.size() == 1) { | 95 | 59 | return _nums.back(); | 96 | 34 | } | 97 | 34 | | 98 | | double u = (_nums.size() - 1) * quantile; | 99 | 25 | auto index = static_cast<uint32_t>(u); | 100 | 25 | return _nums[index] + | 101 | 25 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 25 | static_cast<double>(_nums[index])); | 103 | 25 | } else { | 104 | 59 | DCHECK(_nums.empty()); | 105 | 2 | size_t rows = 0; | 106 | 2 | for (const auto& i : _sorted_nums_vec) { | 107 | 4 | rows += i.size(); | 108 | 4 | } | 109 | 4 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 2 | double u = (rows - 1) * quantile; | 111 | 2 | auto index = static_cast<uint32_t>(u); | 112 | 2 | // if reverse, the step of target should start 0 like not reverse | 113 | | // so here rows need to minus index + 2 | 114 | | // eg: rows = 10, index = 5 | 115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 116 | | // if reverse, so the second number is 3, the first number is 4 | 117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 119 | | size_t target = reverse ? rows - index - 2 : index; | 120 | 2 | if (quantile == 1) { | 121 | 2 | target = 0; | 122 | 0 | } | 123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 2 | if (quantile == 1) { | 125 | 2 | return second_number; | 126 | 0 | } | 127 | 0 | return first_number + | 128 | 2 | (u - static_cast<double>(index)) * | 129 | 2 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 2 | } | 131 | 2 | } | 132 | 61 | |
_ZN5doris6CountsIsE9terminateEd Line | Count | Source | 79 | 300 | if (_sorted_nums_vec.size() <= 1) { | 80 | 300 | if (_sorted_nums_vec.size() == 1) { | 81 | 295 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 1 | } | 83 | 1 | | 84 | | if (_nums.empty()) { | 85 | 295 | // Although set null here, but the value is 0.0 and the call method just | 86 | | // get val in aggregate_function_percentile_approx.h | 87 | | return 0.0; | 88 | 0 | } | 89 | 0 | | 90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 295 | pdqsort(_nums.begin(), _nums.end()); | 92 | 144 | } | 93 | 144 | | 94 | | if (quantile == 1 || _nums.size() == 1) { | 95 | 295 | return _nums.back(); | 96 | 87 | } | 97 | 87 | | 98 | | double u = (_nums.size() - 1) * quantile; | 99 | 208 | auto index = static_cast<uint32_t>(u); | 100 | 208 | return _nums[index] + | 101 | 208 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 208 | static_cast<double>(_nums[index])); | 103 | 208 | } else { | 104 | 295 | DCHECK(_nums.empty()); | 105 | 5 | size_t rows = 0; | 106 | 5 | for (const auto& i : _sorted_nums_vec) { | 107 | 13 | rows += i.size(); | 108 | 13 | } | 109 | 13 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 5 | double u = (rows - 1) * quantile; | 111 | 5 | auto index = static_cast<uint32_t>(u); | 112 | 5 | // if reverse, the step of target should start 0 like not reverse | 113 | | // so here rows need to minus index + 2 | 114 | | // eg: rows = 10, index = 5 | 115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 116 | | // if reverse, so the second number is 3, the first number is 4 | 117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 119 | | size_t target = reverse ? rows - index - 2 : index; | 120 | 5 | if (quantile == 1) { | 121 | 5 | target = 0; | 122 | 0 | } | 123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 5 | if (quantile == 1) { | 125 | 5 | return second_number; | 126 | 0 | } | 127 | 0 | return first_number + | 128 | 5 | (u - static_cast<double>(index)) * | 129 | 5 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 5 | } | 131 | 5 | } | 132 | 300 | |
_ZN5doris6CountsIiE9terminateEd Line | Count | Source | 79 | 444 | if (_sorted_nums_vec.size() <= 1) { | 80 | 444 | if (_sorted_nums_vec.size() == 1) { | 81 | 345 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 227 | } | 83 | 227 | | 84 | | if (_nums.empty()) { | 85 | 345 | // Although set null here, but the value is 0.0 and the call method just | 86 | | // get val in aggregate_function_percentile_approx.h | 87 | | return 0.0; | 88 | 0 | } | 89 | 0 | | 90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 345 | pdqsort(_nums.begin(), _nums.end()); | 92 | 11 | } | 93 | 11 | | 94 | | if (quantile == 1 || _nums.size() == 1) { | 95 | 345 | return _nums.back(); | 96 | 239 | } | 97 | 239 | | 98 | | double u = (_nums.size() - 1) * quantile; | 99 | 106 | auto index = static_cast<uint32_t>(u); | 100 | 106 | return _nums[index] + | 101 | 106 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 106 | static_cast<double>(_nums[index])); | 103 | 106 | } else { | 104 | 345 | DCHECK(_nums.empty()); | 105 | 99 | size_t rows = 0; | 106 | 99 | for (const auto& i : _sorted_nums_vec) { | 107 | 271 | rows += i.size(); | 108 | 271 | } | 109 | 271 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 99 | double u = (rows - 1) * quantile; | 111 | 99 | auto index = static_cast<uint32_t>(u); | 112 | 99 | // if reverse, the step of target should start 0 like not reverse | 113 | | // so here rows need to minus index + 2 | 114 | | // eg: rows = 10, index = 5 | 115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 116 | | // if reverse, so the second number is 3, the first number is 4 | 117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 119 | | size_t target = reverse ? rows - index - 2 : index; | 120 | 99 | if (quantile == 1) { | 121 | 99 | target = 0; | 122 | 0 | } | 123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 99 | if (quantile == 1) { | 125 | 99 | return second_number; | 126 | 0 | } | 127 | 0 | return first_number + | 128 | 99 | (u - static_cast<double>(index)) * | 129 | 99 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 99 | } | 131 | 99 | } | 132 | 444 | |
_ZN5doris6CountsIlE9terminateEd Line | Count | Source | 79 | 128 | if (_sorted_nums_vec.size() <= 1) { | 80 | 128 | if (_sorted_nums_vec.size() == 1) { | 81 | 104 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 34 | } | 83 | 34 | | 84 | | if (_nums.empty()) { | 85 | 104 | // Although set null here, but the value is 0.0 and the call method just | 86 | | // get val in aggregate_function_percentile_approx.h | 87 | | return 0.0; | 88 | 0 | } | 89 | 0 | | 90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 104 | pdqsort(_nums.begin(), _nums.end()); | 92 | 1 | } | 93 | 1 | | 94 | | if (quantile == 1 || _nums.size() == 1) { | 95 | 104 | return _nums.back(); | 96 | 59 | } | 97 | 59 | | 98 | | double u = (_nums.size() - 1) * quantile; | 99 | 45 | auto index = static_cast<uint32_t>(u); | 100 | 45 | return _nums[index] + | 101 | 45 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 45 | static_cast<double>(_nums[index])); | 103 | 45 | } else { | 104 | 104 | DCHECK(_nums.empty()); | 105 | 24 | size_t rows = 0; | 106 | 24 | for (const auto& i : _sorted_nums_vec) { | 107 | 62 | rows += i.size(); | 108 | 62 | } | 109 | 62 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 24 | double u = (rows - 1) * quantile; | 111 | 24 | auto index = static_cast<uint32_t>(u); | 112 | 24 | // if reverse, the step of target should start 0 like not reverse | 113 | | // so here rows need to minus index + 2 | 114 | | // eg: rows = 10, index = 5 | 115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 116 | | // if reverse, so the second number is 3, the first number is 4 | 117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 119 | | size_t target = reverse ? rows - index - 2 : index; | 120 | 24 | if (quantile == 1) { | 121 | 24 | target = 0; | 122 | 0 | } | 123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 24 | if (quantile == 1) { | 125 | 24 | return second_number; | 126 | 0 | } | 127 | 0 | return first_number + | 128 | 24 | (u - static_cast<double>(index)) * | 129 | 24 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 24 | } | 131 | 24 | } | 132 | 128 | |
_ZN5doris6CountsInE9terminateEd Line | Count | Source | 79 | 33 | if (_sorted_nums_vec.size() <= 1) { | 80 | 33 | if (_sorted_nums_vec.size() == 1) { | 81 | 31 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 1 | } | 83 | 1 | | 84 | | if (_nums.empty()) { | 85 | 31 | // Although set null here, but the value is 0.0 and the call method just | 86 | | // get val in aggregate_function_percentile_approx.h | 87 | | return 0.0; | 88 | 0 | } | 89 | 0 | | 90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 31 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | 0 | | 94 | | if (quantile == 1 || _nums.size() == 1) { | 95 | 31 | return _nums.back(); | 96 | 24 | } | 97 | 24 | | 98 | | double u = (_nums.size() - 1) * quantile; | 99 | 7 | auto index = static_cast<uint32_t>(u); | 100 | 7 | return _nums[index] + | 101 | 7 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 7 | static_cast<double>(_nums[index])); | 103 | 7 | } else { | 104 | 31 | DCHECK(_nums.empty()); | 105 | 2 | size_t rows = 0; | 106 | 2 | for (const auto& i : _sorted_nums_vec) { | 107 | 4 | rows += i.size(); | 108 | 4 | } | 109 | 4 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 2 | double u = (rows - 1) * quantile; | 111 | 2 | auto index = static_cast<uint32_t>(u); | 112 | 2 | // if reverse, the step of target should start 0 like not reverse | 113 | | // so here rows need to minus index + 2 | 114 | | // eg: rows = 10, index = 5 | 115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 116 | | // if reverse, so the second number is 3, the first number is 4 | 117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 119 | | size_t target = reverse ? rows - index - 2 : index; | 120 | 2 | if (quantile == 1) { | 121 | 2 | target = 0; | 122 | 0 | } | 123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 2 | if (quantile == 1) { | 125 | 2 | return second_number; | 126 | 0 | } | 127 | 0 | return first_number + | 128 | 2 | (u - static_cast<double>(index)) * | 129 | 2 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 2 | } | 131 | 2 | } | 132 | 33 | |
_ZN5doris6CountsIfE9terminateEd Line | Count | Source | 79 | 3 | if (_sorted_nums_vec.size() <= 1) { | 80 | 3 | if (_sorted_nums_vec.size() == 1) { | 81 | 1 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 1 | } | 83 | 1 | | 84 | | if (_nums.empty()) { | 85 | 1 | // Although set null here, but the value is 0.0 and the call method just | 86 | | // get val in aggregate_function_percentile_approx.h | 87 | | return 0.0; | 88 | 0 | } | 89 | 0 | | 90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 1 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | 0 | | 94 | | if (quantile == 1 || _nums.size() == 1) { | 95 | 1 | return _nums.back(); | 96 | 0 | } | 97 | 0 | | 98 | | double u = (_nums.size() - 1) * quantile; | 99 | 1 | auto index = static_cast<uint32_t>(u); | 100 | 1 | return _nums[index] + | 101 | 1 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 1 | static_cast<double>(_nums[index])); | 103 | 1 | } else { | 104 | 2 | DCHECK(_nums.empty()); | 105 | 2 | size_t rows = 0; | 106 | 2 | for (const auto& i : _sorted_nums_vec) { | 107 | 4 | rows += i.size(); | 108 | 4 | } | 109 | 4 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 2 | double u = (rows - 1) * quantile; | 111 | 2 | auto index = static_cast<uint32_t>(u); | 112 | 2 | // if reverse, the step of target should start 0 like not reverse | 113 | | // so here rows need to minus index + 2 | 114 | | // eg: rows = 10, index = 5 | 115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 116 | | // if reverse, so the second number is 3, the first number is 4 | 117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 119 | | size_t target = reverse ? rows - index - 2 : index; | 120 | 2 | if (quantile == 1) { | 121 | 2 | target = 0; | 122 | 0 | } | 123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 2 | if (quantile == 1) { | 125 | 2 | return second_number; | 126 | 0 | } | 127 | 0 | return first_number + | 128 | 2 | (u - static_cast<double>(index)) * | 129 | 2 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 2 | } | 131 | 2 | } | 132 | 3 | |
_ZN5doris6CountsIdE9terminateEd Line | Count | Source | 79 | 136 | if (_sorted_nums_vec.size() <= 1) { | 80 | 136 | if (_sorted_nums_vec.size() == 1) { | 81 | 110 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 27 | } | 83 | 27 | | 84 | | if (_nums.empty()) { | 85 | 110 | // Although set null here, but the value is 0.0 and the call method just | 86 | | // get val in aggregate_function_percentile_approx.h | 87 | | return 0.0; | 88 | 0 | } | 89 | 0 | | 90 | | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 110 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | 0 | | 94 | | if (quantile == 1 || _nums.size() == 1) { | 95 | 110 | return _nums.back(); | 96 | 30 | } | 97 | 30 | | 98 | | double u = (_nums.size() - 1) * quantile; | 99 | 80 | auto index = static_cast<uint32_t>(u); | 100 | 80 | return _nums[index] + | 101 | 80 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 80 | static_cast<double>(_nums[index])); | 103 | 80 | } else { | 104 | 110 | DCHECK(_nums.empty()); | 105 | 26 | size_t rows = 0; | 106 | 26 | for (const auto& i : _sorted_nums_vec) { | 107 | 64 | rows += i.size(); | 108 | 64 | } | 109 | 64 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 26 | double u = (rows - 1) * quantile; | 111 | 26 | auto index = static_cast<uint32_t>(u); | 112 | 26 | // if reverse, the step of target should start 0 like not reverse | 113 | | // so here rows need to minus index + 2 | 114 | | // eg: rows = 10, index = 5 | 115 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 116 | | // if reverse, so the second number is 3, the first number is 4 | 117 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 118 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 119 | | size_t target = reverse ? rows - index - 2 : index; | 120 | 26 | if (quantile == 1) { | 121 | 26 | target = 0; | 122 | 0 | } | 123 | 0 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 26 | if (quantile == 1) { | 125 | 26 | return second_number; | 126 | 0 | } | 127 | 0 | return first_number + | 128 | 26 | (u - static_cast<double>(index)) * | 129 | 26 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 26 | } | 131 | 26 | } | 132 | 136 | |
|
133 | | private: |
134 | | struct Node { |
135 | | Ty value; |
136 | | int array_index; |
137 | | int64_t element_index; |
138 | | |
139 | | auto operator<=>(const Node& other) const { return value <=> other.value; } |
140 | 1.41k | }; _ZNK5doris6CountsIaE4NodessERKS2_ Line | Count | Source | 140 | 4 | }; |
_ZNK5doris6CountsIsE4NodessERKS2_ Line | Count | Source | 140 | 42 | }; |
_ZNK5doris6CountsIiE4NodessERKS2_ Line | Count | Source | 140 | 942 | }; |
_ZNK5doris6CountsIlE4NodessERKS2_ Line | Count | Source | 140 | 359 | }; |
_ZNK5doris6CountsInE4NodessERKS2_ Line | Count | Source | 140 | 4 | }; |
_ZNK5doris6CountsIfE4NodessERKS2_ Line | Count | Source | 140 | 4 | }; |
_ZNK5doris6CountsIdE4NodessERKS2_ Line | Count | Source | 140 | 62 | }; |
|
141 | | |
142 | | void _convert_sorted_num_vec_to_nums() { |
143 | 265 | size_t rows = 0; |
144 | 265 | for (const auto& i : _sorted_nums_vec) { |
145 | 558 | rows += i.size(); |
146 | 558 | } |
147 | 558 | _nums.resize(rows); |
148 | 265 | size_t count = 0; |
149 | 265 | |
150 | | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
151 | 265 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
152 | 823 | if (!_sorted_nums_vec[i].empty()) { |
153 | 558 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
154 | 558 | } |
155 | 558 | } |
156 | 558 | |
157 | | while (!min_heap.empty()) { |
158 | 975 | Node node = min_heap.top(); |
159 | 710 | min_heap.pop(); |
160 | 710 | _nums[count++] = node.value; |
161 | 710 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
162 | 710 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
163 | 152 | min_heap.push(node); |
164 | 152 | } |
165 | 152 | } |
166 | 710 | _sorted_nums_vec.clear(); |
167 | 265 | } |
168 | 265 | 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 | 143 | 156 | size_t rows = 0; | 144 | 156 | for (const auto& i : _sorted_nums_vec) { | 145 | 339 | rows += i.size(); | 146 | 339 | } | 147 | 339 | _nums.resize(rows); | 148 | 156 | size_t count = 0; | 149 | 156 | | 150 | | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 151 | 156 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 152 | 495 | if (!_sorted_nums_vec[i].empty()) { | 153 | 339 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 154 | 339 | } | 155 | 339 | } | 156 | 339 | | 157 | | while (!min_heap.empty()) { | 158 | 531 | Node node = min_heap.top(); | 159 | 375 | min_heap.pop(); | 160 | 375 | _nums[count++] = node.value; | 161 | 375 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 162 | 375 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 163 | 36 | min_heap.push(node); | 164 | 36 | } | 165 | 36 | } | 166 | 375 | _sorted_nums_vec.clear(); | 167 | 156 | } | 168 | 156 | |
_ZN5doris6CountsIlE31_convert_sorted_num_vec_to_numsEv Line | Count | Source | 143 | 109 | size_t rows = 0; | 144 | 109 | for (const auto& i : _sorted_nums_vec) { | 145 | 219 | rows += i.size(); | 146 | 219 | } | 147 | 219 | _nums.resize(rows); | 148 | 109 | size_t count = 0; | 149 | 109 | | 150 | | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 151 | 109 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 152 | 328 | if (!_sorted_nums_vec[i].empty()) { | 153 | 219 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 154 | 219 | } | 155 | 219 | } | 156 | 219 | | 157 | | while (!min_heap.empty()) { | 158 | 444 | Node node = min_heap.top(); | 159 | 335 | min_heap.pop(); | 160 | 335 | _nums[count++] = node.value; | 161 | 335 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 162 | 335 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 163 | 116 | min_heap.push(node); | 164 | 116 | } | 165 | 116 | } | 166 | 335 | _sorted_nums_vec.clear(); | 167 | 109 | } | 168 | 109 | |
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 |
169 | | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { |
170 | 160 | Ty first_number = 0, second_number = 0; |
171 | 160 | size_t count = 0; |
172 | 160 | if (reverse) { |
173 | 160 | std::priority_queue<Node> max_heap; |
174 | 35 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
175 | 128 | if (!_sorted_nums_vec[i].empty()) { |
176 | 93 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, |
177 | 93 | _sorted_nums_vec[i].size() - 1); |
178 | 93 | } |
179 | 93 | } |
180 | 93 | |
181 | | while (!max_heap.empty()) { |
182 | 127 | Node node = max_heap.top(); |
183 | 127 | max_heap.pop(); |
184 | 127 | if (count == target) { |
185 | 127 | second_number = node.value; |
186 | 35 | } else if (count == target + 1) { |
187 | 92 | first_number = node.value; |
188 | 35 | break; |
189 | 35 | } |
190 | 35 | ++count; |
191 | 92 | if (--node.element_index >= 0) { |
192 | 92 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
193 | 78 | max_heap.push(node); |
194 | 78 | } |
195 | 78 | } |
196 | 92 | |
197 | | } else { |
198 | 125 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
199 | 125 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
200 | 454 | if (!_sorted_nums_vec[i].empty()) { |
201 | 329 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
202 | 329 | } |
203 | 329 | } |
204 | 329 | |
205 | | while (!min_heap.empty()) { |
206 | 352 | Node node = min_heap.top(); |
207 | 352 | min_heap.pop(); |
208 | 352 | if (count == target) { |
209 | 352 | first_number = node.value; |
210 | 125 | } else if (count == target + 1) { |
211 | 227 | second_number = node.value; |
212 | 125 | break; |
213 | 125 | } |
214 | 125 | ++count; |
215 | 227 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
216 | 227 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
217 | 138 | min_heap.push(node); |
218 | 138 | } |
219 | 138 | } |
220 | 227 | } |
221 | 125 | |
222 | | return {first_number, second_number}; |
223 | 160 | } |
224 | 160 | _ZN5doris6CountsIaE27_merge_sort_and_get_numbersElb Line | Count | Source | 170 | 2 | Ty first_number = 0, second_number = 0; | 171 | 2 | size_t count = 0; | 172 | 2 | if (reverse) { | 173 | 2 | std::priority_queue<Node> max_heap; | 174 | 1 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 3 | if (!_sorted_nums_vec[i].empty()) { | 176 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 2 | _sorted_nums_vec[i].size() - 1); | 178 | 2 | } | 179 | 2 | } | 180 | 2 | | 181 | | while (!max_heap.empty()) { | 182 | 2 | Node node = max_heap.top(); | 183 | 2 | max_heap.pop(); | 184 | 2 | if (count == target) { | 185 | 2 | second_number = node.value; | 186 | 1 | } else if (count == target + 1) { | 187 | 1 | first_number = node.value; | 188 | 1 | break; | 189 | 1 | } | 190 | 1 | ++count; | 191 | 1 | if (--node.element_index >= 0) { | 192 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 1 | } | 196 | 1 | | 197 | | } else { | 198 | 1 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 1 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 3 | if (!_sorted_nums_vec[i].empty()) { | 201 | 2 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 2 | } | 203 | 2 | } | 204 | 2 | | 205 | | while (!min_heap.empty()) { | 206 | 3 | Node node = min_heap.top(); | 207 | 3 | min_heap.pop(); | 208 | 3 | if (count == target) { | 209 | 3 | first_number = node.value; | 210 | 1 | } else if (count == target + 1) { | 211 | 2 | second_number = node.value; | 212 | 1 | break; | 213 | 1 | } | 214 | 1 | ++count; | 215 | 2 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 1 | min_heap.push(node); | 218 | 1 | } | 219 | 1 | } | 220 | 2 | } | 221 | 1 | | 222 | | return {first_number, second_number}; | 223 | 2 | } | 224 | 2 | |
_ZN5doris6CountsIsE27_merge_sort_and_get_numbersElb Line | Count | Source | 170 | 5 | Ty first_number = 0, second_number = 0; | 171 | 5 | size_t count = 0; | 172 | 5 | if (reverse) { | 173 | 5 | std::priority_queue<Node> max_heap; | 174 | 2 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 7 | if (!_sorted_nums_vec[i].empty()) { | 176 | 5 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 5 | _sorted_nums_vec[i].size() - 1); | 178 | 5 | } | 179 | 5 | } | 180 | 5 | | 181 | | while (!max_heap.empty()) { | 182 | 8 | Node node = max_heap.top(); | 183 | 8 | max_heap.pop(); | 184 | 8 | if (count == target) { | 185 | 8 | second_number = node.value; | 186 | 2 | } else if (count == target + 1) { | 187 | 6 | first_number = node.value; | 188 | 2 | break; | 189 | 2 | } | 190 | 2 | ++count; | 191 | 6 | if (--node.element_index >= 0) { | 192 | 6 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 5 | max_heap.push(node); | 194 | 5 | } | 195 | 5 | } | 196 | 6 | | 197 | | } else { | 198 | 3 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 11 | if (!_sorted_nums_vec[i].empty()) { | 201 | 8 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 8 | } | 203 | 8 | } | 204 | 8 | | 205 | | while (!min_heap.empty()) { | 206 | 16 | Node node = min_heap.top(); | 207 | 16 | min_heap.pop(); | 208 | 16 | if (count == target) { | 209 | 16 | first_number = node.value; | 210 | 3 | } else if (count == target + 1) { | 211 | 13 | second_number = node.value; | 212 | 3 | break; | 213 | 3 | } | 214 | 3 | ++count; | 215 | 13 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 13 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 12 | min_heap.push(node); | 218 | 12 | } | 219 | 12 | } | 220 | 13 | } | 221 | 3 | | 222 | | return {first_number, second_number}; | 223 | 5 | } | 224 | 5 | |
_ZN5doris6CountsIiE27_merge_sort_and_get_numbersElb Line | Count | Source | 170 | 99 | Ty first_number = 0, second_number = 0; | 171 | 99 | size_t count = 0; | 172 | 99 | if (reverse) { | 173 | 99 | std::priority_queue<Node> max_heap; | 174 | 11 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 41 | if (!_sorted_nums_vec[i].empty()) { | 176 | 30 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 30 | _sorted_nums_vec[i].size() - 1); | 178 | 30 | } | 179 | 30 | } | 180 | 30 | | 181 | | while (!max_heap.empty()) { | 182 | 41 | Node node = max_heap.top(); | 183 | 41 | max_heap.pop(); | 184 | 41 | if (count == target) { | 185 | 41 | second_number = node.value; | 186 | 11 | } else if (count == target + 1) { | 187 | 30 | first_number = node.value; | 188 | 11 | break; | 189 | 11 | } | 190 | 11 | ++count; | 191 | 30 | if (--node.element_index >= 0) { | 192 | 30 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 23 | max_heap.push(node); | 194 | 23 | } | 195 | 23 | } | 196 | 30 | | 197 | | } else { | 198 | 88 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 88 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 329 | if (!_sorted_nums_vec[i].empty()) { | 201 | 241 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 241 | } | 203 | 241 | } | 204 | 241 | | 205 | | while (!min_heap.empty()) { | 206 | 247 | Node node = min_heap.top(); | 207 | 247 | min_heap.pop(); | 208 | 247 | if (count == target) { | 209 | 247 | first_number = node.value; | 210 | 88 | } else if (count == target + 1) { | 211 | 159 | second_number = node.value; | 212 | 88 | break; | 213 | 88 | } | 214 | 88 | ++count; | 215 | 159 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 159 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 99 | min_heap.push(node); | 218 | 99 | } | 219 | 99 | } | 220 | 159 | } | 221 | 88 | | 222 | | return {first_number, second_number}; | 223 | 99 | } | 224 | 99 | |
_ZN5doris6CountsIlE27_merge_sort_and_get_numbersElb Line | Count | Source | 170 | 24 | Ty first_number = 0, second_number = 0; | 171 | 24 | size_t count = 0; | 172 | 24 | if (reverse) { | 173 | 24 | std::priority_queue<Node> max_heap; | 174 | 16 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 60 | if (!_sorted_nums_vec[i].empty()) { | 176 | 44 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 44 | _sorted_nums_vec[i].size() - 1); | 178 | 44 | } | 179 | 44 | } | 180 | 44 | | 181 | | while (!max_heap.empty()) { | 182 | 65 | Node node = max_heap.top(); | 183 | 65 | max_heap.pop(); | 184 | 65 | if (count == target) { | 185 | 65 | second_number = node.value; | 186 | 16 | } else if (count == target + 1) { | 187 | 49 | first_number = node.value; | 188 | 16 | break; | 189 | 16 | } | 190 | 16 | ++count; | 191 | 49 | if (--node.element_index >= 0) { | 192 | 49 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 46 | max_heap.push(node); | 194 | 46 | } | 195 | 46 | } | 196 | 49 | | 197 | | } else { | 198 | 16 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 8 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 26 | if (!_sorted_nums_vec[i].empty()) { | 201 | 18 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 18 | } | 203 | 18 | } | 204 | 18 | | 205 | | while (!min_heap.empty()) { | 206 | 25 | Node node = min_heap.top(); | 207 | 25 | min_heap.pop(); | 208 | 25 | if (count == target) { | 209 | 25 | first_number = node.value; | 210 | 8 | } else if (count == target + 1) { | 211 | 17 | second_number = node.value; | 212 | 8 | break; | 213 | 8 | } | 214 | 8 | ++count; | 215 | 17 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 17 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 15 | min_heap.push(node); | 218 | 15 | } | 219 | 15 | } | 220 | 17 | } | 221 | 8 | | 222 | | return {first_number, second_number}; | 223 | 24 | } | 224 | 24 | |
_ZN5doris6CountsInE27_merge_sort_and_get_numbersElb Line | Count | Source | 170 | 2 | Ty first_number = 0, second_number = 0; | 171 | 2 | size_t count = 0; | 172 | 2 | if (reverse) { | 173 | 2 | std::priority_queue<Node> max_heap; | 174 | 1 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 3 | if (!_sorted_nums_vec[i].empty()) { | 176 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 2 | _sorted_nums_vec[i].size() - 1); | 178 | 2 | } | 179 | 2 | } | 180 | 2 | | 181 | | while (!max_heap.empty()) { | 182 | 2 | Node node = max_heap.top(); | 183 | 2 | max_heap.pop(); | 184 | 2 | if (count == target) { | 185 | 2 | second_number = node.value; | 186 | 1 | } else if (count == target + 1) { | 187 | 1 | first_number = node.value; | 188 | 1 | break; | 189 | 1 | } | 190 | 1 | ++count; | 191 | 1 | if (--node.element_index >= 0) { | 192 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 1 | } | 196 | 1 | | 197 | | } else { | 198 | 1 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 1 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 3 | if (!_sorted_nums_vec[i].empty()) { | 201 | 2 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 2 | } | 203 | 2 | } | 204 | 2 | | 205 | | while (!min_heap.empty()) { | 206 | 3 | Node node = min_heap.top(); | 207 | 3 | min_heap.pop(); | 208 | 3 | if (count == target) { | 209 | 3 | first_number = node.value; | 210 | 1 | } else if (count == target + 1) { | 211 | 2 | second_number = node.value; | 212 | 1 | break; | 213 | 1 | } | 214 | 1 | ++count; | 215 | 2 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 1 | min_heap.push(node); | 218 | 1 | } | 219 | 1 | } | 220 | 2 | } | 221 | 1 | | 222 | | return {first_number, second_number}; | 223 | 2 | } | 224 | 2 | |
_ZN5doris6CountsIfE27_merge_sort_and_get_numbersElb Line | Count | Source | 170 | 2 | Ty first_number = 0, second_number = 0; | 171 | 2 | size_t count = 0; | 172 | 2 | if (reverse) { | 173 | 2 | std::priority_queue<Node> max_heap; | 174 | 1 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 3 | if (!_sorted_nums_vec[i].empty()) { | 176 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 2 | _sorted_nums_vec[i].size() - 1); | 178 | 2 | } | 179 | 2 | } | 180 | 2 | | 181 | | while (!max_heap.empty()) { | 182 | 2 | Node node = max_heap.top(); | 183 | 2 | max_heap.pop(); | 184 | 2 | if (count == target) { | 185 | 2 | second_number = node.value; | 186 | 1 | } else if (count == target + 1) { | 187 | 1 | first_number = node.value; | 188 | 1 | break; | 189 | 1 | } | 190 | 1 | ++count; | 191 | 1 | if (--node.element_index >= 0) { | 192 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 1 | } | 196 | 1 | | 197 | | } else { | 198 | 1 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 1 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 3 | if (!_sorted_nums_vec[i].empty()) { | 201 | 2 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 2 | } | 203 | 2 | } | 204 | 2 | | 205 | | while (!min_heap.empty()) { | 206 | 3 | Node node = min_heap.top(); | 207 | 3 | min_heap.pop(); | 208 | 3 | if (count == target) { | 209 | 3 | first_number = node.value; | 210 | 1 | } else if (count == target + 1) { | 211 | 2 | second_number = node.value; | 212 | 1 | break; | 213 | 1 | } | 214 | 1 | ++count; | 215 | 2 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 1 | min_heap.push(node); | 218 | 1 | } | 219 | 1 | } | 220 | 2 | } | 221 | 1 | | 222 | | return {first_number, second_number}; | 223 | 2 | } | 224 | 2 | |
_ZN5doris6CountsIdE27_merge_sort_and_get_numbersElb Line | Count | Source | 170 | 26 | Ty first_number = 0, second_number = 0; | 171 | 26 | size_t count = 0; | 172 | 26 | if (reverse) { | 173 | 26 | std::priority_queue<Node> max_heap; | 174 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 11 | if (!_sorted_nums_vec[i].empty()) { | 176 | 8 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 8 | _sorted_nums_vec[i].size() - 1); | 178 | 8 | } | 179 | 8 | } | 180 | 8 | | 181 | | while (!max_heap.empty()) { | 182 | 7 | Node node = max_heap.top(); | 183 | 7 | max_heap.pop(); | 184 | 7 | if (count == target) { | 185 | 7 | second_number = node.value; | 186 | 3 | } else if (count == target + 1) { | 187 | 4 | first_number = node.value; | 188 | 3 | break; | 189 | 3 | } | 190 | 3 | ++count; | 191 | 4 | if (--node.element_index >= 0) { | 192 | 4 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 1 | } | 196 | 4 | | 197 | | } else { | 198 | 23 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 23 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 79 | if (!_sorted_nums_vec[i].empty()) { | 201 | 56 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 56 | } | 203 | 56 | } | 204 | 56 | | 205 | | while (!min_heap.empty()) { | 206 | 55 | Node node = min_heap.top(); | 207 | 55 | min_heap.pop(); | 208 | 55 | if (count == target) { | 209 | 55 | first_number = node.value; | 210 | 23 | } else if (count == target + 1) { | 211 | 32 | second_number = node.value; | 212 | 23 | break; | 213 | 23 | } | 214 | 23 | ++count; | 215 | 32 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 32 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 9 | min_heap.push(node); | 218 | 9 | } | 219 | 9 | } | 220 | 32 | } | 221 | 23 | | 222 | | return {first_number, second_number}; | 223 | 26 | } | 224 | 26 | |
|
225 | | vectorized::PODArray<Ty> _nums; |
226 | | std::vector<vectorized::PODArray<Ty>> _sorted_nums_vec; |
227 | | }; |
228 | | |
229 | | } // namespace doris |