/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 | | |
29 | | namespace doris { |
30 | | |
31 | | template <typename Ty> |
32 | | class Counts { |
33 | | public: |
34 | 3.69k | Counts() = default; Line | Count | Source | 34 | 49 | Counts() = default; |
Line | Count | Source | 34 | 219 | Counts() = default; |
Line | Count | Source | 34 | 2.23k | Counts() = default; |
Line | Count | Source | 34 | 843 | Counts() = default; |
Line | Count | Source | 34 | 45 | Counts() = default; |
Line | Count | Source | 34 | 15 | Counts() = default; |
Line | Count | Source | 34 | 284 | Counts() = default; |
|
35 | | |
36 | 1.32k | void merge(Counts* other) { |
37 | 1.32k | if (other != nullptr && !other->_nums.empty()) { |
38 | 1.32k | _sorted_nums_vec.emplace_back(std::move(other->_nums)); |
39 | 1.32k | } |
40 | 1.32k | } _ZN5doris6CountsIaE5mergeEPS1_ Line | Count | Source | 36 | 6 | void merge(Counts* other) { | 37 | 6 | if (other != nullptr && !other->_nums.empty()) { | 38 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 39 | 6 | } | 40 | 6 | } |
_ZN5doris6CountsIsE5mergeEPS1_ Line | Count | Source | 36 | 18 | void merge(Counts* other) { | 37 | 18 | if (other != nullptr && !other->_nums.empty()) { | 38 | 18 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 39 | 18 | } | 40 | 18 | } |
_ZN5doris6CountsIiE5mergeEPS1_ Line | Count | Source | 36 | 838 | void merge(Counts* other) { | 37 | 838 | if (other != nullptr && !other->_nums.empty()) { | 38 | 838 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 39 | 838 | } | 40 | 838 | } |
_ZN5doris6CountsIlE5mergeEPS1_ Line | Count | Source | 36 | 354 | void merge(Counts* other) { | 37 | 354 | if (other != nullptr && !other->_nums.empty()) { | 38 | 354 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 39 | 354 | } | 40 | 354 | } |
_ZN5doris6CountsInE5mergeEPS1_ Line | Count | Source | 36 | 6 | void merge(Counts* other) { | 37 | 6 | if (other != nullptr && !other->_nums.empty()) { | 38 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 39 | 6 | } | 40 | 6 | } |
_ZN5doris6CountsIfE5mergeEPS1_ Line | Count | Source | 36 | 6 | void merge(Counts* other) { | 37 | 6 | if (other != nullptr && !other->_nums.empty()) { | 38 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 39 | 6 | } | 40 | 6 | } |
_ZN5doris6CountsIdE5mergeEPS1_ Line | Count | Source | 36 | 98 | void merge(Counts* other) { | 37 | 98 | if (other != nullptr && !other->_nums.empty()) { | 38 | 98 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 39 | 98 | } | 40 | 98 | } |
|
41 | | |
42 | | void increment(Ty key, uint32_t i) { |
43 | | auto old_size = _nums.size(); |
44 | | _nums.resize(_nums.size() + i); |
45 | | for (uint32_t j = 0; j < i; ++j) { |
46 | | _nums[old_size + j] = key; |
47 | | } |
48 | | } |
49 | | |
50 | 2.93k | void increment(Ty key) { _nums.push_back(key); }_ZN5doris6CountsIaE9incrementEa Line | Count | Source | 50 | 73 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIsE9incrementEs Line | Count | Source | 50 | 552 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIiE9incrementEi Line | Count | Source | 50 | 1.59k | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIlE9incrementEl Line | Count | Source | 50 | 401 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsInE9incrementEn Line | Count | Source | 50 | 45 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIfE9incrementEf Line | Count | Source | 50 | 9 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIdE9incrementEd Line | Count | Source | 50 | 259 | void increment(Ty key) { _nums.push_back(key); } |
|
51 | | |
52 | 5 | void increment_batch(const PaddedPODArray<Ty>& keys) { _nums.insert(keys.begin(), keys.end()); }Unexecuted instantiation: _ZN5doris6CountsIaE15increment_batchERKNS_8PODArrayIaLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIsE15increment_batchERKNS_8PODArrayIsLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIiE15increment_batchERKNS_8PODArrayIiLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE _ZN5doris6CountsIlE15increment_batchERKNS_8PODArrayIlLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Line | Count | Source | 52 | 5 | void increment_batch(const PaddedPODArray<Ty>& keys) { _nums.insert(keys.begin(), keys.end()); } |
Unexecuted instantiation: _ZN5doris6CountsInE15increment_batchERKNS_8PODArrayInLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIfE15increment_batchERKNS_8PODArrayIfLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIdE15increment_batchERKNS_8PODArrayIdLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb1EEELm16ELm15EEE |
53 | | |
54 | 1.73k | void serialize(BufferWritable& buf) { |
55 | 1.73k | if (!_nums.empty()) { |
56 | 1.44k | pdqsort(_nums.begin(), _nums.end()); |
57 | 1.44k | size_t size = _nums.size(); |
58 | 1.44k | buf.write_binary(size); |
59 | 1.44k | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); |
60 | 1.44k | } else { |
61 | | // convert _sorted_nums_vec to _nums and do seiralize again |
62 | 288 | _convert_sorted_num_vec_to_nums(); |
63 | 288 | serialize(buf); |
64 | 288 | } |
65 | 1.73k | } _ZN5doris6CountsIaE9serializeERNS_14BufferWritableE Line | Count | Source | 54 | 6 | void serialize(BufferWritable& buf) { | 55 | 6 | if (!_nums.empty()) { | 56 | 6 | pdqsort(_nums.begin(), _nums.end()); | 57 | 6 | size_t size = _nums.size(); | 58 | 6 | buf.write_binary(size); | 59 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 60 | 6 | } else { | 61 | | // convert _sorted_nums_vec to _nums and do seiralize again | 62 | 0 | _convert_sorted_num_vec_to_nums(); | 63 | 0 | serialize(buf); | 64 | 0 | } | 65 | 6 | } |
_ZN5doris6CountsIsE9serializeERNS_14BufferWritableE Line | Count | Source | 54 | 18 | void serialize(BufferWritable& buf) { | 55 | 18 | if (!_nums.empty()) { | 56 | 18 | pdqsort(_nums.begin(), _nums.end()); | 57 | 18 | size_t size = _nums.size(); | 58 | 18 | buf.write_binary(size); | 59 | 18 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 60 | 18 | } else { | 61 | | // convert _sorted_nums_vec to _nums and do seiralize again | 62 | 0 | _convert_sorted_num_vec_to_nums(); | 63 | 0 | serialize(buf); | 64 | 0 | } | 65 | 18 | } |
_ZN5doris6CountsIiE9serializeERNS_14BufferWritableE Line | Count | Source | 54 | 1.11k | void serialize(BufferWritable& buf) { | 55 | 1.11k | if (!_nums.empty()) { | 56 | 955 | pdqsort(_nums.begin(), _nums.end()); | 57 | 955 | size_t size = _nums.size(); | 58 | 955 | buf.write_binary(size); | 59 | 955 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 60 | 955 | } else { | 61 | | // convert _sorted_nums_vec to _nums and do seiralize again | 62 | 156 | _convert_sorted_num_vec_to_nums(); | 63 | 156 | serialize(buf); | 64 | 156 | } | 65 | 1.11k | } |
_ZN5doris6CountsIlE9serializeERNS_14BufferWritableE Line | Count | Source | 54 | 486 | void serialize(BufferWritable& buf) { | 55 | 486 | if (!_nums.empty()) { | 56 | 354 | pdqsort(_nums.begin(), _nums.end()); | 57 | 354 | size_t size = _nums.size(); | 58 | 354 | buf.write_binary(size); | 59 | 354 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 60 | 354 | } else { | 61 | | // convert _sorted_nums_vec to _nums and do seiralize again | 62 | 132 | _convert_sorted_num_vec_to_nums(); | 63 | 132 | serialize(buf); | 64 | 132 | } | 65 | 486 | } |
_ZN5doris6CountsInE9serializeERNS_14BufferWritableE Line | Count | Source | 54 | 6 | void serialize(BufferWritable& buf) { | 55 | 6 | if (!_nums.empty()) { | 56 | 6 | pdqsort(_nums.begin(), _nums.end()); | 57 | 6 | size_t size = _nums.size(); | 58 | 6 | buf.write_binary(size); | 59 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 60 | 6 | } else { | 61 | | // convert _sorted_nums_vec to _nums and do seiralize again | 62 | 0 | _convert_sorted_num_vec_to_nums(); | 63 | 0 | serialize(buf); | 64 | 0 | } | 65 | 6 | } |
_ZN5doris6CountsIfE9serializeERNS_14BufferWritableE Line | Count | Source | 54 | 6 | void serialize(BufferWritable& buf) { | 55 | 6 | if (!_nums.empty()) { | 56 | 6 | pdqsort(_nums.begin(), _nums.end()); | 57 | 6 | size_t size = _nums.size(); | 58 | 6 | buf.write_binary(size); | 59 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 60 | 6 | } else { | 61 | | // convert _sorted_nums_vec to _nums and do seiralize again | 62 | 0 | _convert_sorted_num_vec_to_nums(); | 63 | 0 | serialize(buf); | 64 | 0 | } | 65 | 6 | } |
_ZN5doris6CountsIdE9serializeERNS_14BufferWritableE Line | Count | Source | 54 | 98 | void serialize(BufferWritable& buf) { | 55 | 98 | if (!_nums.empty()) { | 56 | 98 | pdqsort(_nums.begin(), _nums.end()); | 57 | 98 | size_t size = _nums.size(); | 58 | 98 | buf.write_binary(size); | 59 | 98 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 60 | 98 | } else { | 61 | | // convert _sorted_nums_vec to _nums and do seiralize again | 62 | 0 | _convert_sorted_num_vec_to_nums(); | 63 | 0 | serialize(buf); | 64 | 0 | } | 65 | 98 | } |
|
66 | | |
67 | 1.32k | void unserialize(BufferReadable& buf) { |
68 | 1.32k | size_t size; |
69 | 1.32k | buf.read_binary(size); |
70 | 1.32k | _nums.resize(size); |
71 | 1.32k | auto buff = buf.read(sizeof(Ty) * size); |
72 | 1.32k | memcpy(_nums.data(), buff.data, buff.size); |
73 | 1.32k | } _ZN5doris6CountsIaE11unserializeERNS_14BufferReadableE Line | Count | Source | 67 | 6 | void unserialize(BufferReadable& buf) { | 68 | 6 | size_t size; | 69 | 6 | buf.read_binary(size); | 70 | 6 | _nums.resize(size); | 71 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 72 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 73 | 6 | } |
_ZN5doris6CountsIsE11unserializeERNS_14BufferReadableE Line | Count | Source | 67 | 18 | void unserialize(BufferReadable& buf) { | 68 | 18 | size_t size; | 69 | 18 | buf.read_binary(size); | 70 | 18 | _nums.resize(size); | 71 | 18 | auto buff = buf.read(sizeof(Ty) * size); | 72 | 18 | memcpy(_nums.data(), buff.data, buff.size); | 73 | 18 | } |
_ZN5doris6CountsIiE11unserializeERNS_14BufferReadableE Line | Count | Source | 67 | 838 | void unserialize(BufferReadable& buf) { | 68 | 838 | size_t size; | 69 | 838 | buf.read_binary(size); | 70 | 838 | _nums.resize(size); | 71 | 838 | auto buff = buf.read(sizeof(Ty) * size); | 72 | 838 | memcpy(_nums.data(), buff.data, buff.size); | 73 | 838 | } |
_ZN5doris6CountsIlE11unserializeERNS_14BufferReadableE Line | Count | Source | 67 | 354 | void unserialize(BufferReadable& buf) { | 68 | 354 | size_t size; | 69 | 354 | buf.read_binary(size); | 70 | 354 | _nums.resize(size); | 71 | 354 | auto buff = buf.read(sizeof(Ty) * size); | 72 | 354 | memcpy(_nums.data(), buff.data, buff.size); | 73 | 354 | } |
_ZN5doris6CountsInE11unserializeERNS_14BufferReadableE Line | Count | Source | 67 | 6 | void unserialize(BufferReadable& buf) { | 68 | 6 | size_t size; | 69 | 6 | buf.read_binary(size); | 70 | 6 | _nums.resize(size); | 71 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 72 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 73 | 6 | } |
_ZN5doris6CountsIfE11unserializeERNS_14BufferReadableE Line | Count | Source | 67 | 6 | void unserialize(BufferReadable& buf) { | 68 | 6 | size_t size; | 69 | 6 | buf.read_binary(size); | 70 | 6 | _nums.resize(size); | 71 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 72 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 73 | 6 | } |
_ZN5doris6CountsIdE11unserializeERNS_14BufferReadableE Line | Count | Source | 67 | 98 | void unserialize(BufferReadable& buf) { | 68 | 98 | size_t size; | 69 | 98 | buf.read_binary(size); | 70 | 98 | _nums.resize(size); | 71 | 98 | auto buff = buf.read(sizeof(Ty) * size); | 72 | 98 | memcpy(_nums.data(), buff.data, buff.size); | 73 | 98 | } |
|
74 | | |
75 | 1.10k | double terminate(double quantile) { |
76 | 1.10k | if (_sorted_nums_vec.size() <= 1) { |
77 | 938 | if (_sorted_nums_vec.size() == 1) { |
78 | 285 | _nums = std::move(_sorted_nums_vec[0]); |
79 | 285 | } |
80 | | |
81 | 938 | if (_nums.empty()) { |
82 | | // Although set null here, but the value is 0.0 and the call method just |
83 | | // get val in aggregate_function_percentile_approx.h |
84 | 0 | return 0.0; |
85 | 0 | } |
86 | | |
87 | 938 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { |
88 | 180 | pdqsort(_nums.begin(), _nums.end()); |
89 | 180 | } |
90 | | |
91 | 938 | if (quantile == 1 || _nums.size() == 1) { |
92 | 473 | return _nums.back(); |
93 | 473 | } |
94 | | |
95 | 465 | double u = (_nums.size() - 1) * quantile; |
96 | 465 | auto index = static_cast<uint32_t>(u); |
97 | 465 | return _nums[index] + |
98 | 465 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - |
99 | 465 | static_cast<double>(_nums[index])); |
100 | 938 | } else { |
101 | 167 | DCHECK(_nums.empty()); |
102 | 167 | size_t rows = 0; |
103 | 455 | for (const auto& i : _sorted_nums_vec) { |
104 | 455 | rows += i.size(); |
105 | 455 | } |
106 | 167 | const bool reverse = quantile > 0.5 && rows > 2; |
107 | 167 | double u = (rows - 1) * quantile; |
108 | 167 | auto index = static_cast<uint32_t>(u); |
109 | | // if reverse, the step of target should start 0 like not reverse |
110 | | // so here rows need to minus index + 2 |
111 | | // eg: rows = 10, index = 5 |
112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 |
113 | | // if reverse, so the second number is 3, the first number is 4 |
114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. |
115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 |
116 | 167 | size_t target = reverse ? rows - index - 2 : index; |
117 | 167 | if (quantile == 1) { |
118 | 0 | target = 0; |
119 | 0 | } |
120 | 167 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); |
121 | 167 | if (quantile == 1) { |
122 | 0 | return second_number; |
123 | 0 | } |
124 | 167 | return first_number + |
125 | 167 | (u - static_cast<double>(index)) * |
126 | 167 | (static_cast<double>(second_number) - static_cast<double>(first_number)); |
127 | 167 | } |
128 | 1.10k | } _ZN5doris6CountsIaE9terminateEd Line | Count | Source | 75 | 61 | double terminate(double quantile) { | 76 | 61 | if (_sorted_nums_vec.size() <= 1) { | 77 | 58 | if (_sorted_nums_vec.size() == 1) { | 78 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 79 | 0 | } | 80 | | | 81 | 58 | if (_nums.empty()) { | 82 | | // Although set null here, but the value is 0.0 and the call method just | 83 | | // get val in aggregate_function_percentile_approx.h | 84 | 0 | return 0.0; | 85 | 0 | } | 86 | | | 87 | 58 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 88 | 24 | pdqsort(_nums.begin(), _nums.end()); | 89 | 24 | } | 90 | | | 91 | 58 | if (quantile == 1 || _nums.size() == 1) { | 92 | 34 | return _nums.back(); | 93 | 34 | } | 94 | | | 95 | 24 | double u = (_nums.size() - 1) * quantile; | 96 | 24 | auto index = static_cast<uint32_t>(u); | 97 | 24 | return _nums[index] + | 98 | 24 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 99 | 24 | static_cast<double>(_nums[index])); | 100 | 58 | } else { | 101 | 3 | DCHECK(_nums.empty()); | 102 | 3 | size_t rows = 0; | 103 | 6 | for (const auto& i : _sorted_nums_vec) { | 104 | 6 | rows += i.size(); | 105 | 6 | } | 106 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 107 | 3 | double u = (rows - 1) * quantile; | 108 | 3 | auto index = static_cast<uint32_t>(u); | 109 | | // if reverse, the step of target should start 0 like not reverse | 110 | | // so here rows need to minus index + 2 | 111 | | // eg: rows = 10, index = 5 | 112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 113 | | // if reverse, so the second number is 3, the first number is 4 | 114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 116 | 3 | size_t target = reverse ? rows - index - 2 : index; | 117 | 3 | if (quantile == 1) { | 118 | 0 | target = 0; | 119 | 0 | } | 120 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 121 | 3 | if (quantile == 1) { | 122 | 0 | return second_number; | 123 | 0 | } | 124 | 3 | return first_number + | 125 | 3 | (u - static_cast<double>(index)) * | 126 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 127 | 3 | } | 128 | 61 | } |
_ZN5doris6CountsIsE9terminateEd Line | Count | Source | 75 | 300 | double terminate(double quantile) { | 76 | 300 | if (_sorted_nums_vec.size() <= 1) { | 77 | 294 | if (_sorted_nums_vec.size() == 1) { | 78 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 79 | 0 | } | 80 | | | 81 | 294 | if (_nums.empty()) { | 82 | | // Although set null here, but the value is 0.0 and the call method just | 83 | | // get val in aggregate_function_percentile_approx.h | 84 | 0 | return 0.0; | 85 | 0 | } | 86 | | | 87 | 294 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 88 | 144 | pdqsort(_nums.begin(), _nums.end()); | 89 | 144 | } | 90 | | | 91 | 294 | if (quantile == 1 || _nums.size() == 1) { | 92 | 87 | return _nums.back(); | 93 | 87 | } | 94 | | | 95 | 207 | double u = (_nums.size() - 1) * quantile; | 96 | 207 | auto index = static_cast<uint32_t>(u); | 97 | 207 | return _nums[index] + | 98 | 207 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 99 | 207 | static_cast<double>(_nums[index])); | 100 | 294 | } else { | 101 | 6 | DCHECK(_nums.empty()); | 102 | 6 | size_t rows = 0; | 103 | 18 | for (const auto& i : _sorted_nums_vec) { | 104 | 18 | rows += i.size(); | 105 | 18 | } | 106 | 6 | const bool reverse = quantile > 0.5 && rows > 2; | 107 | 6 | double u = (rows - 1) * quantile; | 108 | 6 | auto index = static_cast<uint32_t>(u); | 109 | | // if reverse, the step of target should start 0 like not reverse | 110 | | // so here rows need to minus index + 2 | 111 | | // eg: rows = 10, index = 5 | 112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 113 | | // if reverse, so the second number is 3, the first number is 4 | 114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 116 | 6 | size_t target = reverse ? rows - index - 2 : index; | 117 | 6 | if (quantile == 1) { | 118 | 0 | target = 0; | 119 | 0 | } | 120 | 6 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 121 | 6 | if (quantile == 1) { | 122 | 0 | return second_number; | 123 | 0 | } | 124 | 6 | return first_number + | 125 | 6 | (u - static_cast<double>(index)) * | 126 | 6 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 127 | 6 | } | 128 | 300 | } |
_ZN5doris6CountsIiE9terminateEd Line | Count | Source | 75 | 444 | double terminate(double quantile) { | 76 | 444 | if (_sorted_nums_vec.size() <= 1) { | 77 | 344 | if (_sorted_nums_vec.size() == 1) { | 78 | 226 | _nums = std::move(_sorted_nums_vec[0]); | 79 | 226 | } | 80 | | | 81 | 344 | if (_nums.empty()) { | 82 | | // Although set null here, but the value is 0.0 and the call method just | 83 | | // get val in aggregate_function_percentile_approx.h | 84 | 0 | return 0.0; | 85 | 0 | } | 86 | | | 87 | 344 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 88 | 11 | pdqsort(_nums.begin(), _nums.end()); | 89 | 11 | } | 90 | | | 91 | 344 | if (quantile == 1 || _nums.size() == 1) { | 92 | 239 | return _nums.back(); | 93 | 239 | } | 94 | | | 95 | 105 | double u = (_nums.size() - 1) * quantile; | 96 | 105 | auto index = static_cast<uint32_t>(u); | 97 | 105 | return _nums[index] + | 98 | 105 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 99 | 105 | static_cast<double>(_nums[index])); | 100 | 344 | } else { | 101 | 100 | DCHECK(_nums.empty()); | 102 | 100 | size_t rows = 0; | 103 | 273 | for (const auto& i : _sorted_nums_vec) { | 104 | 273 | rows += i.size(); | 105 | 273 | } | 106 | 100 | const bool reverse = quantile > 0.5 && rows > 2; | 107 | 100 | double u = (rows - 1) * quantile; | 108 | 100 | auto index = static_cast<uint32_t>(u); | 109 | | // if reverse, the step of target should start 0 like not reverse | 110 | | // so here rows need to minus index + 2 | 111 | | // eg: rows = 10, index = 5 | 112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 113 | | // if reverse, so the second number is 3, the first number is 4 | 114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 116 | 100 | size_t target = reverse ? rows - index - 2 : index; | 117 | 100 | if (quantile == 1) { | 118 | 0 | target = 0; | 119 | 0 | } | 120 | 100 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 121 | 100 | if (quantile == 1) { | 122 | 0 | return second_number; | 123 | 0 | } | 124 | 100 | return first_number + | 125 | 100 | (u - static_cast<double>(index)) * | 126 | 100 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 127 | 100 | } | 128 | 444 | } |
_ZN5doris6CountsIlE9terminateEd Line | Count | Source | 75 | 128 | double terminate(double quantile) { | 76 | 128 | if (_sorted_nums_vec.size() <= 1) { | 77 | 103 | if (_sorted_nums_vec.size() == 1) { | 78 | 33 | _nums = std::move(_sorted_nums_vec[0]); | 79 | 33 | } | 80 | | | 81 | 103 | if (_nums.empty()) { | 82 | | // Although set null here, but the value is 0.0 and the call method just | 83 | | // get val in aggregate_function_percentile_approx.h | 84 | 0 | return 0.0; | 85 | 0 | } | 86 | | | 87 | 103 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 88 | 1 | pdqsort(_nums.begin(), _nums.end()); | 89 | 1 | } | 90 | | | 91 | 103 | if (quantile == 1 || _nums.size() == 1) { | 92 | 59 | return _nums.back(); | 93 | 59 | } | 94 | | | 95 | 44 | double u = (_nums.size() - 1) * quantile; | 96 | 44 | auto index = static_cast<uint32_t>(u); | 97 | 44 | return _nums[index] + | 98 | 44 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 99 | 44 | static_cast<double>(_nums[index])); | 100 | 103 | } else { | 101 | 25 | DCHECK(_nums.empty()); | 102 | 25 | size_t rows = 0; | 103 | 74 | for (const auto& i : _sorted_nums_vec) { | 104 | 74 | rows += i.size(); | 105 | 74 | } | 106 | 25 | const bool reverse = quantile > 0.5 && rows > 2; | 107 | 25 | double u = (rows - 1) * quantile; | 108 | 25 | auto index = static_cast<uint32_t>(u); | 109 | | // if reverse, the step of target should start 0 like not reverse | 110 | | // so here rows need to minus index + 2 | 111 | | // eg: rows = 10, index = 5 | 112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 113 | | // if reverse, so the second number is 3, the first number is 4 | 114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 116 | 25 | size_t target = reverse ? rows - index - 2 : index; | 117 | 25 | if (quantile == 1) { | 118 | 0 | target = 0; | 119 | 0 | } | 120 | 25 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 121 | 25 | if (quantile == 1) { | 122 | 0 | return second_number; | 123 | 0 | } | 124 | 25 | return first_number + | 125 | 25 | (u - static_cast<double>(index)) * | 126 | 25 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 127 | 25 | } | 128 | 128 | } |
_ZN5doris6CountsInE9terminateEd Line | Count | Source | 75 | 33 | double terminate(double quantile) { | 76 | 33 | if (_sorted_nums_vec.size() <= 1) { | 77 | 30 | if (_sorted_nums_vec.size() == 1) { | 78 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 79 | 0 | } | 80 | | | 81 | 30 | if (_nums.empty()) { | 82 | | // Although set null here, but the value is 0.0 and the call method just | 83 | | // get val in aggregate_function_percentile_approx.h | 84 | 0 | return 0.0; | 85 | 0 | } | 86 | | | 87 | 30 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 88 | 0 | pdqsort(_nums.begin(), _nums.end()); | 89 | 0 | } | 90 | | | 91 | 30 | if (quantile == 1 || _nums.size() == 1) { | 92 | 24 | return _nums.back(); | 93 | 24 | } | 94 | | | 95 | 6 | double u = (_nums.size() - 1) * quantile; | 96 | 6 | auto index = static_cast<uint32_t>(u); | 97 | 6 | return _nums[index] + | 98 | 6 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 99 | 6 | static_cast<double>(_nums[index])); | 100 | 30 | } else { | 101 | 3 | DCHECK(_nums.empty()); | 102 | 3 | size_t rows = 0; | 103 | 6 | for (const auto& i : _sorted_nums_vec) { | 104 | 6 | rows += i.size(); | 105 | 6 | } | 106 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 107 | 3 | double u = (rows - 1) * quantile; | 108 | 3 | auto index = static_cast<uint32_t>(u); | 109 | | // if reverse, the step of target should start 0 like not reverse | 110 | | // so here rows need to minus index + 2 | 111 | | // eg: rows = 10, index = 5 | 112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 113 | | // if reverse, so the second number is 3, the first number is 4 | 114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 116 | 3 | size_t target = reverse ? rows - index - 2 : index; | 117 | 3 | if (quantile == 1) { | 118 | 0 | target = 0; | 119 | 0 | } | 120 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 121 | 3 | if (quantile == 1) { | 122 | 0 | return second_number; | 123 | 0 | } | 124 | 3 | return first_number + | 125 | 3 | (u - static_cast<double>(index)) * | 126 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 127 | 3 | } | 128 | 33 | } |
_ZN5doris6CountsIfE9terminateEd Line | Count | Source | 75 | 3 | double terminate(double quantile) { | 76 | 3 | if (_sorted_nums_vec.size() <= 1) { | 77 | 0 | if (_sorted_nums_vec.size() == 1) { | 78 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 79 | 0 | } | 80 | |
| 81 | 0 | if (_nums.empty()) { | 82 | | // Although set null here, but the value is 0.0 and the call method just | 83 | | // get val in aggregate_function_percentile_approx.h | 84 | 0 | return 0.0; | 85 | 0 | } | 86 | | | 87 | 0 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 88 | 0 | pdqsort(_nums.begin(), _nums.end()); | 89 | 0 | } | 90 | |
| 91 | 0 | if (quantile == 1 || _nums.size() == 1) { | 92 | 0 | return _nums.back(); | 93 | 0 | } | 94 | | | 95 | 0 | double u = (_nums.size() - 1) * quantile; | 96 | 0 | auto index = static_cast<uint32_t>(u); | 97 | 0 | return _nums[index] + | 98 | 0 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 99 | 0 | static_cast<double>(_nums[index])); | 100 | 3 | } else { | 101 | 3 | DCHECK(_nums.empty()); | 102 | 3 | size_t rows = 0; | 103 | 6 | for (const auto& i : _sorted_nums_vec) { | 104 | 6 | rows += i.size(); | 105 | 6 | } | 106 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 107 | 3 | double u = (rows - 1) * quantile; | 108 | 3 | auto index = static_cast<uint32_t>(u); | 109 | | // if reverse, the step of target should start 0 like not reverse | 110 | | // so here rows need to minus index + 2 | 111 | | // eg: rows = 10, index = 5 | 112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 113 | | // if reverse, so the second number is 3, the first number is 4 | 114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 116 | 3 | size_t target = reverse ? rows - index - 2 : index; | 117 | 3 | if (quantile == 1) { | 118 | 0 | target = 0; | 119 | 0 | } | 120 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 121 | 3 | if (quantile == 1) { | 122 | 0 | return second_number; | 123 | 0 | } | 124 | 3 | return first_number + | 125 | 3 | (u - static_cast<double>(index)) * | 126 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 127 | 3 | } | 128 | 3 | } |
_ZN5doris6CountsIdE9terminateEd Line | Count | Source | 75 | 136 | double terminate(double quantile) { | 76 | 136 | if (_sorted_nums_vec.size() <= 1) { | 77 | 109 | if (_sorted_nums_vec.size() == 1) { | 78 | 26 | _nums = std::move(_sorted_nums_vec[0]); | 79 | 26 | } | 80 | | | 81 | 109 | if (_nums.empty()) { | 82 | | // Although set null here, but the value is 0.0 and the call method just | 83 | | // get val in aggregate_function_percentile_approx.h | 84 | 0 | return 0.0; | 85 | 0 | } | 86 | | | 87 | 109 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 88 | 0 | pdqsort(_nums.begin(), _nums.end()); | 89 | 0 | } | 90 | | | 91 | 109 | if (quantile == 1 || _nums.size() == 1) { | 92 | 30 | return _nums.back(); | 93 | 30 | } | 94 | | | 95 | 79 | double u = (_nums.size() - 1) * quantile; | 96 | 79 | auto index = static_cast<uint32_t>(u); | 97 | 79 | return _nums[index] + | 98 | 79 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 99 | 79 | static_cast<double>(_nums[index])); | 100 | 109 | } else { | 101 | 27 | DCHECK(_nums.empty()); | 102 | 27 | size_t rows = 0; | 103 | 72 | for (const auto& i : _sorted_nums_vec) { | 104 | 72 | rows += i.size(); | 105 | 72 | } | 106 | 27 | const bool reverse = quantile > 0.5 && rows > 2; | 107 | 27 | double u = (rows - 1) * quantile; | 108 | 27 | auto index = static_cast<uint32_t>(u); | 109 | | // if reverse, the step of target should start 0 like not reverse | 110 | | // so here rows need to minus index + 2 | 111 | | // eg: rows = 10, index = 5 | 112 | | // if not reverse, so the first number loc is 5, the second number loc is 6 | 113 | | // if reverse, so the second number is 3, the first number is 4 | 114 | | // 5 + 4 = 3 + 6 = 9 = rows - 1. | 115 | | // the rows must GE 2 beacuse `_sorted_nums_vec` size GE 2 | 116 | 27 | size_t target = reverse ? rows - index - 2 : index; | 117 | 27 | if (quantile == 1) { | 118 | 0 | target = 0; | 119 | 0 | } | 120 | 27 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 121 | 27 | if (quantile == 1) { | 122 | 0 | return second_number; | 123 | 0 | } | 124 | 27 | return first_number + | 125 | 27 | (u - static_cast<double>(index)) * | 126 | 27 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 127 | 27 | } | 128 | 136 | } |
|
129 | | |
130 | | private: |
131 | | struct Node { |
132 | | Ty value; |
133 | | int array_index; |
134 | | int64_t element_index; |
135 | | |
136 | 1.52k | auto operator<=>(const Node& other) const { return value <=> other.value; }_ZNK5doris6CountsIaE4NodessERKS2_ Line | Count | Source | 136 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIsE4NodessERKS2_ Line | Count | Source | 136 | 73 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIiE4NodessERKS2_ Line | Count | Source | 136 | 934 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIlE4NodessERKS2_ Line | Count | Source | 136 | 425 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsInE4NodessERKS2_ Line | Count | Source | 136 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIfE4NodessERKS2_ Line | Count | Source | 136 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIdE4NodessERKS2_ Line | Count | Source | 136 | 79 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
|
137 | | }; |
138 | | |
139 | 288 | void _convert_sorted_num_vec_to_nums() { |
140 | 288 | size_t rows = 0; |
141 | 586 | for (const auto& i : _sorted_nums_vec) { |
142 | 586 | rows += i.size(); |
143 | 586 | } |
144 | 288 | _nums.resize(rows); |
145 | 288 | size_t count = 0; |
146 | | |
147 | 288 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
148 | 874 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
149 | 586 | if (!_sorted_nums_vec[i].empty()) { |
150 | 586 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
151 | 586 | } |
152 | 586 | } |
153 | | |
154 | 1.02k | while (!min_heap.empty()) { |
155 | 737 | Node node = min_heap.top(); |
156 | 737 | min_heap.pop(); |
157 | 737 | _nums[count++] = node.value; |
158 | 737 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
159 | 151 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
160 | 151 | min_heap.push(node); |
161 | 151 | } |
162 | 737 | } |
163 | 288 | _sorted_nums_vec.clear(); |
164 | 288 | } 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 | 139 | 156 | void _convert_sorted_num_vec_to_nums() { | 140 | 156 | size_t rows = 0; | 141 | 339 | for (const auto& i : _sorted_nums_vec) { | 142 | 339 | rows += i.size(); | 143 | 339 | } | 144 | 156 | _nums.resize(rows); | 145 | 156 | size_t count = 0; | 146 | | | 147 | 156 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 148 | 495 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 149 | 339 | if (!_sorted_nums_vec[i].empty()) { | 150 | 339 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 151 | 339 | } | 152 | 339 | } | 153 | | | 154 | 531 | while (!min_heap.empty()) { | 155 | 375 | Node node = min_heap.top(); | 156 | 375 | min_heap.pop(); | 157 | 375 | _nums[count++] = node.value; | 158 | 375 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 159 | 36 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 160 | 36 | min_heap.push(node); | 161 | 36 | } | 162 | 375 | } | 163 | 156 | _sorted_nums_vec.clear(); | 164 | 156 | } |
_ZN5doris6CountsIlE31_convert_sorted_num_vec_to_numsEv Line | Count | Source | 139 | 132 | void _convert_sorted_num_vec_to_nums() { | 140 | 132 | size_t rows = 0; | 141 | 247 | for (const auto& i : _sorted_nums_vec) { | 142 | 247 | rows += i.size(); | 143 | 247 | } | 144 | 132 | _nums.resize(rows); | 145 | 132 | size_t count = 0; | 146 | | | 147 | 132 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 148 | 379 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 149 | 247 | if (!_sorted_nums_vec[i].empty()) { | 150 | 247 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 151 | 247 | } | 152 | 247 | } | 153 | | | 154 | 494 | while (!min_heap.empty()) { | 155 | 362 | Node node = min_heap.top(); | 156 | 362 | min_heap.pop(); | 157 | 362 | _nums[count++] = node.value; | 158 | 362 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 159 | 115 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 160 | 115 | min_heap.push(node); | 161 | 115 | } | 162 | 362 | } | 163 | 132 | _sorted_nums_vec.clear(); | 164 | 132 | } |
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 |
165 | | |
166 | 167 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { |
167 | 167 | Ty first_number = 0, second_number = 0; |
168 | 167 | size_t count = 0; |
169 | 167 | if (reverse) { |
170 | 35 | std::priority_queue<Node> max_heap; |
171 | 140 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
172 | 105 | if (!_sorted_nums_vec[i].empty()) { |
173 | 105 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, |
174 | 105 | _sorted_nums_vec[i].size() - 1); |
175 | 105 | } |
176 | 105 | } |
177 | | |
178 | 127 | while (!max_heap.empty()) { |
179 | 127 | Node node = max_heap.top(); |
180 | 127 | max_heap.pop(); |
181 | 127 | if (count == target) { |
182 | 35 | second_number = node.value; |
183 | 92 | } else if (count == target + 1) { |
184 | 35 | first_number = node.value; |
185 | 35 | break; |
186 | 35 | } |
187 | 92 | ++count; |
188 | 92 | if (--node.element_index >= 0) { |
189 | 74 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
190 | 74 | max_heap.push(node); |
191 | 74 | } |
192 | 92 | } |
193 | | |
194 | 132 | } else { |
195 | 132 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
196 | 482 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
197 | 350 | if (!_sorted_nums_vec[i].empty()) { |
198 | 350 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
199 | 350 | } |
200 | 350 | } |
201 | | |
202 | 373 | while (!min_heap.empty()) { |
203 | 373 | Node node = min_heap.top(); |
204 | 373 | min_heap.pop(); |
205 | 373 | if (count == target) { |
206 | 132 | first_number = node.value; |
207 | 241 | } else if (count == target + 1) { |
208 | 132 | second_number = node.value; |
209 | 132 | break; |
210 | 132 | } |
211 | 241 | ++count; |
212 | 241 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
213 | 141 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
214 | 141 | min_heap.push(node); |
215 | 141 | } |
216 | 241 | } |
217 | 132 | } |
218 | | |
219 | 167 | return {first_number, second_number}; |
220 | 167 | } _ZN5doris6CountsIaE27_merge_sort_and_get_numbersElb Line | Count | Source | 166 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 167 | 3 | Ty first_number = 0, second_number = 0; | 168 | 3 | size_t count = 0; | 169 | 3 | if (reverse) { | 170 | 1 | std::priority_queue<Node> max_heap; | 171 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 172 | 2 | if (!_sorted_nums_vec[i].empty()) { | 173 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 174 | 2 | _sorted_nums_vec[i].size() - 1); | 175 | 2 | } | 176 | 2 | } | 177 | | | 178 | 2 | while (!max_heap.empty()) { | 179 | 2 | Node node = max_heap.top(); | 180 | 2 | max_heap.pop(); | 181 | 2 | if (count == target) { | 182 | 1 | second_number = node.value; | 183 | 1 | } else if (count == target + 1) { | 184 | 1 | first_number = node.value; | 185 | 1 | break; | 186 | 1 | } | 187 | 1 | ++count; | 188 | 1 | if (--node.element_index >= 0) { | 189 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 190 | 1 | max_heap.push(node); | 191 | 1 | } | 192 | 1 | } | 193 | | | 194 | 2 | } else { | 195 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 196 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 197 | 4 | if (!_sorted_nums_vec[i].empty()) { | 198 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 199 | 4 | } | 200 | 4 | } | 201 | | | 202 | 6 | while (!min_heap.empty()) { | 203 | 6 | Node node = min_heap.top(); | 204 | 6 | min_heap.pop(); | 205 | 6 | if (count == target) { | 206 | 2 | first_number = node.value; | 207 | 4 | } else if (count == target + 1) { | 208 | 2 | second_number = node.value; | 209 | 2 | break; | 210 | 2 | } | 211 | 4 | ++count; | 212 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 213 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 214 | 2 | min_heap.push(node); | 215 | 2 | } | 216 | 4 | } | 217 | 2 | } | 218 | | | 219 | 3 | return {first_number, second_number}; | 220 | 3 | } |
_ZN5doris6CountsIsE27_merge_sort_and_get_numbersElb Line | Count | Source | 166 | 6 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 167 | 6 | Ty first_number = 0, second_number = 0; | 168 | 6 | size_t count = 0; | 169 | 6 | if (reverse) { | 170 | 2 | std::priority_queue<Node> max_heap; | 171 | 8 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 172 | 6 | if (!_sorted_nums_vec[i].empty()) { | 173 | 6 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 174 | 6 | _sorted_nums_vec[i].size() - 1); | 175 | 6 | } | 176 | 6 | } | 177 | | | 178 | 8 | while (!max_heap.empty()) { | 179 | 8 | Node node = max_heap.top(); | 180 | 8 | max_heap.pop(); | 181 | 8 | if (count == target) { | 182 | 2 | second_number = node.value; | 183 | 6 | } else if (count == target + 1) { | 184 | 2 | first_number = node.value; | 185 | 2 | break; | 186 | 2 | } | 187 | 6 | ++count; | 188 | 6 | if (--node.element_index >= 0) { | 189 | 4 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 190 | 4 | max_heap.push(node); | 191 | 4 | } | 192 | 6 | } | 193 | | | 194 | 4 | } else { | 195 | 4 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 196 | 16 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 197 | 12 | if (!_sorted_nums_vec[i].empty()) { | 198 | 12 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 199 | 12 | } | 200 | 12 | } | 201 | | | 202 | 19 | while (!min_heap.empty()) { | 203 | 19 | Node node = min_heap.top(); | 204 | 19 | min_heap.pop(); | 205 | 19 | if (count == target) { | 206 | 4 | first_number = node.value; | 207 | 15 | } else if (count == target + 1) { | 208 | 4 | second_number = node.value; | 209 | 4 | break; | 210 | 4 | } | 211 | 15 | ++count; | 212 | 15 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 213 | 13 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 214 | 13 | min_heap.push(node); | 215 | 13 | } | 216 | 15 | } | 217 | 4 | } | 218 | | | 219 | 6 | return {first_number, second_number}; | 220 | 6 | } |
_ZN5doris6CountsIiE27_merge_sort_and_get_numbersElb Line | Count | Source | 166 | 100 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 167 | 100 | Ty first_number = 0, second_number = 0; | 168 | 100 | size_t count = 0; | 169 | 100 | if (reverse) { | 170 | 11 | std::priority_queue<Node> max_heap; | 171 | 41 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 172 | 30 | if (!_sorted_nums_vec[i].empty()) { | 173 | 30 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 174 | 30 | _sorted_nums_vec[i].size() - 1); | 175 | 30 | } | 176 | 30 | } | 177 | | | 178 | 41 | while (!max_heap.empty()) { | 179 | 41 | Node node = max_heap.top(); | 180 | 41 | max_heap.pop(); | 181 | 41 | if (count == target) { | 182 | 11 | second_number = node.value; | 183 | 30 | } else if (count == target + 1) { | 184 | 11 | first_number = node.value; | 185 | 11 | break; | 186 | 11 | } | 187 | 30 | ++count; | 188 | 30 | if (--node.element_index >= 0) { | 189 | 23 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 190 | 23 | max_heap.push(node); | 191 | 23 | } | 192 | 30 | } | 193 | | | 194 | 89 | } else { | 195 | 89 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 196 | 332 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 197 | 243 | if (!_sorted_nums_vec[i].empty()) { | 198 | 243 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 199 | 243 | } | 200 | 243 | } | 201 | | | 202 | 250 | while (!min_heap.empty()) { | 203 | 250 | Node node = min_heap.top(); | 204 | 250 | min_heap.pop(); | 205 | 250 | if (count == target) { | 206 | 89 | first_number = node.value; | 207 | 161 | } else if (count == target + 1) { | 208 | 89 | second_number = node.value; | 209 | 89 | break; | 210 | 89 | } | 211 | 161 | ++count; | 212 | 161 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 213 | 100 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 214 | 100 | min_heap.push(node); | 215 | 100 | } | 216 | 161 | } | 217 | 89 | } | 218 | | | 219 | 100 | return {first_number, second_number}; | 220 | 100 | } |
_ZN5doris6CountsIlE27_merge_sort_and_get_numbersElb Line | Count | Source | 166 | 25 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 167 | 25 | Ty first_number = 0, second_number = 0; | 168 | 25 | size_t count = 0; | 169 | 25 | if (reverse) { | 170 | 16 | std::priority_queue<Node> max_heap; | 171 | 70 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 172 | 54 | if (!_sorted_nums_vec[i].empty()) { | 173 | 54 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 174 | 54 | _sorted_nums_vec[i].size() - 1); | 175 | 54 | } | 176 | 54 | } | 177 | | | 178 | 65 | while (!max_heap.empty()) { | 179 | 65 | Node node = max_heap.top(); | 180 | 65 | max_heap.pop(); | 181 | 65 | if (count == target) { | 182 | 16 | second_number = node.value; | 183 | 49 | } else if (count == target + 1) { | 184 | 16 | first_number = node.value; | 185 | 16 | break; | 186 | 16 | } | 187 | 49 | ++count; | 188 | 49 | if (--node.element_index >= 0) { | 189 | 43 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 190 | 43 | max_heap.push(node); | 191 | 43 | } | 192 | 49 | } | 193 | | | 194 | 16 | } else { | 195 | 9 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 196 | 29 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 197 | 20 | if (!_sorted_nums_vec[i].empty()) { | 198 | 20 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 199 | 20 | } | 200 | 20 | } | 201 | | | 202 | 28 | while (!min_heap.empty()) { | 203 | 28 | Node node = min_heap.top(); | 204 | 28 | min_heap.pop(); | 205 | 28 | if (count == target) { | 206 | 9 | first_number = node.value; | 207 | 19 | } else if (count == target + 1) { | 208 | 9 | second_number = node.value; | 209 | 9 | break; | 210 | 9 | } | 211 | 19 | ++count; | 212 | 19 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 213 | 16 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 214 | 16 | min_heap.push(node); | 215 | 16 | } | 216 | 19 | } | 217 | 9 | } | 218 | | | 219 | 25 | return {first_number, second_number}; | 220 | 25 | } |
_ZN5doris6CountsInE27_merge_sort_and_get_numbersElb Line | Count | Source | 166 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 167 | 3 | Ty first_number = 0, second_number = 0; | 168 | 3 | size_t count = 0; | 169 | 3 | if (reverse) { | 170 | 1 | std::priority_queue<Node> max_heap; | 171 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 172 | 2 | if (!_sorted_nums_vec[i].empty()) { | 173 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 174 | 2 | _sorted_nums_vec[i].size() - 1); | 175 | 2 | } | 176 | 2 | } | 177 | | | 178 | 2 | while (!max_heap.empty()) { | 179 | 2 | Node node = max_heap.top(); | 180 | 2 | max_heap.pop(); | 181 | 2 | if (count == target) { | 182 | 1 | second_number = node.value; | 183 | 1 | } else if (count == target + 1) { | 184 | 1 | first_number = node.value; | 185 | 1 | break; | 186 | 1 | } | 187 | 1 | ++count; | 188 | 1 | if (--node.element_index >= 0) { | 189 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 190 | 1 | max_heap.push(node); | 191 | 1 | } | 192 | 1 | } | 193 | | | 194 | 2 | } else { | 195 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 196 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 197 | 4 | if (!_sorted_nums_vec[i].empty()) { | 198 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 199 | 4 | } | 200 | 4 | } | 201 | | | 202 | 6 | while (!min_heap.empty()) { | 203 | 6 | Node node = min_heap.top(); | 204 | 6 | min_heap.pop(); | 205 | 6 | if (count == target) { | 206 | 2 | first_number = node.value; | 207 | 4 | } else if (count == target + 1) { | 208 | 2 | second_number = node.value; | 209 | 2 | break; | 210 | 2 | } | 211 | 4 | ++count; | 212 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 213 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 214 | 2 | min_heap.push(node); | 215 | 2 | } | 216 | 4 | } | 217 | 2 | } | 218 | | | 219 | 3 | return {first_number, second_number}; | 220 | 3 | } |
_ZN5doris6CountsIfE27_merge_sort_and_get_numbersElb Line | Count | Source | 166 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 167 | 3 | Ty first_number = 0, second_number = 0; | 168 | 3 | size_t count = 0; | 169 | 3 | if (reverse) { | 170 | 1 | std::priority_queue<Node> max_heap; | 171 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 172 | 2 | if (!_sorted_nums_vec[i].empty()) { | 173 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 174 | 2 | _sorted_nums_vec[i].size() - 1); | 175 | 2 | } | 176 | 2 | } | 177 | | | 178 | 2 | while (!max_heap.empty()) { | 179 | 2 | Node node = max_heap.top(); | 180 | 2 | max_heap.pop(); | 181 | 2 | if (count == target) { | 182 | 1 | second_number = node.value; | 183 | 1 | } else if (count == target + 1) { | 184 | 1 | first_number = node.value; | 185 | 1 | break; | 186 | 1 | } | 187 | 1 | ++count; | 188 | 1 | if (--node.element_index >= 0) { | 189 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 190 | 1 | max_heap.push(node); | 191 | 1 | } | 192 | 1 | } | 193 | | | 194 | 2 | } else { | 195 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 196 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 197 | 4 | if (!_sorted_nums_vec[i].empty()) { | 198 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 199 | 4 | } | 200 | 4 | } | 201 | | | 202 | 6 | while (!min_heap.empty()) { | 203 | 6 | Node node = min_heap.top(); | 204 | 6 | min_heap.pop(); | 205 | 6 | if (count == target) { | 206 | 2 | first_number = node.value; | 207 | 4 | } else if (count == target + 1) { | 208 | 2 | second_number = node.value; | 209 | 2 | break; | 210 | 2 | } | 211 | 4 | ++count; | 212 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 213 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 214 | 2 | min_heap.push(node); | 215 | 2 | } | 216 | 4 | } | 217 | 2 | } | 218 | | | 219 | 3 | return {first_number, second_number}; | 220 | 3 | } |
_ZN5doris6CountsIdE27_merge_sort_and_get_numbersElb Line | Count | Source | 166 | 27 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 167 | 27 | Ty first_number = 0, second_number = 0; | 168 | 27 | size_t count = 0; | 169 | 27 | if (reverse) { | 170 | 3 | std::priority_queue<Node> max_heap; | 171 | 12 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 172 | 9 | if (!_sorted_nums_vec[i].empty()) { | 173 | 9 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 174 | 9 | _sorted_nums_vec[i].size() - 1); | 175 | 9 | } | 176 | 9 | } | 177 | | | 178 | 7 | while (!max_heap.empty()) { | 179 | 7 | Node node = max_heap.top(); | 180 | 7 | max_heap.pop(); | 181 | 7 | if (count == target) { | 182 | 3 | second_number = node.value; | 183 | 4 | } else if (count == target + 1) { | 184 | 3 | first_number = node.value; | 185 | 3 | break; | 186 | 3 | } | 187 | 4 | ++count; | 188 | 4 | if (--node.element_index >= 0) { | 189 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 190 | 1 | max_heap.push(node); | 191 | 1 | } | 192 | 4 | } | 193 | | | 194 | 24 | } else { | 195 | 24 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 196 | 87 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 197 | 63 | if (!_sorted_nums_vec[i].empty()) { | 198 | 63 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 199 | 63 | } | 200 | 63 | } | 201 | | | 202 | 58 | while (!min_heap.empty()) { | 203 | 58 | Node node = min_heap.top(); | 204 | 58 | min_heap.pop(); | 205 | 58 | if (count == target) { | 206 | 24 | first_number = node.value; | 207 | 34 | } else if (count == target + 1) { | 208 | 24 | second_number = node.value; | 209 | 24 | break; | 210 | 24 | } | 211 | 34 | ++count; | 212 | 34 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 213 | 6 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 214 | 6 | min_heap.push(node); | 215 | 6 | } | 216 | 34 | } | 217 | 24 | } | 218 | | | 219 | 27 | return {first_number, second_number}; | 220 | 27 | } |
|
221 | | |
222 | | PODArray<Ty> _nums; |
223 | | std::vector<PODArray<Ty>> _sorted_nums_vec; |
224 | | }; |
225 | | |
226 | | } // namespace doris |