/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 | 3.66k | Counts() = default; Line | Count | Source | 35 | 45 | Counts() = default; |
Line | Count | Source | 35 | 215 | Counts() = default; |
Line | Count | Source | 35 | 2.23k | Counts() = default; |
Line | Count | Source | 35 | 847 | Counts() = default; |
Line | Count | Source | 35 | 41 | Counts() = default; |
Line | Count | Source | 35 | 11 | Counts() = default; |
Line | Count | Source | 35 | 266 | Counts() = default; |
|
36 | | |
37 | 1.30k | void merge(Counts* other) { |
38 | 1.30k | if (other != nullptr && !other->_nums.empty()) { |
39 | 1.30k | _sorted_nums_vec.emplace_back(std::move(other->_nums)); |
40 | 1.30k | } |
41 | 1.30k | } _ZN5doris6CountsIaE5mergeEPS1_ Line | Count | Source | 37 | 4 | void merge(Counts* other) { | 38 | 4 | if (other != nullptr && !other->_nums.empty()) { | 39 | 4 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 4 | } | 41 | 4 | } |
_ZN5doris6CountsIsE5mergeEPS1_ Line | Count | Source | 37 | 16 | void merge(Counts* other) { | 38 | 16 | if (other != nullptr && !other->_nums.empty()) { | 39 | 16 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 16 | } | 41 | 16 | } |
_ZN5doris6CountsIiE5mergeEPS1_ Line | Count | Source | 37 | 836 | void merge(Counts* other) { | 38 | 836 | if (other != nullptr && !other->_nums.empty()) { | 39 | 836 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 836 | } | 41 | 836 | } |
_ZN5doris6CountsIlE5mergeEPS1_ Line | Count | Source | 37 | 355 | void merge(Counts* other) { | 38 | 355 | if (other != nullptr && !other->_nums.empty()) { | 39 | 355 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 355 | } | 41 | 355 | } |
_ZN5doris6CountsInE5mergeEPS1_ Line | Count | Source | 37 | 4 | void merge(Counts* other) { | 38 | 4 | if (other != nullptr && !other->_nums.empty()) { | 39 | 4 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 4 | } | 41 | 4 | } |
_ZN5doris6CountsIfE5mergeEPS1_ Line | Count | Source | 37 | 4 | void merge(Counts* other) { | 38 | 4 | if (other != nullptr && !other->_nums.empty()) { | 39 | 4 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 4 | } | 41 | 4 | } |
_ZN5doris6CountsIdE5mergeEPS1_ Line | Count | Source | 37 | 90 | void merge(Counts* other) { | 38 | 90 | if (other != nullptr && !other->_nums.empty()) { | 39 | 90 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 90 | } | 41 | 90 | } |
|
42 | | |
43 | | void increment(Ty key, uint32_t i) { |
44 | | auto old_size = _nums.size(); |
45 | | _nums.resize(_nums.size() + i); |
46 | | for (uint32_t j = 0; j < i; ++j) { |
47 | | _nums[old_size + j] = key; |
48 | | } |
49 | | } |
50 | | |
51 | 2.92k | void increment(Ty key) { _nums.push_back(key); }_ZN5doris6CountsIaE9incrementEa Line | Count | Source | 51 | 73 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIsE9incrementEs Line | Count | Source | 51 | 552 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIiE9incrementEi Line | Count | Source | 51 | 1.59k | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIlE9incrementEl Line | Count | Source | 51 | 401 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsInE9incrementEn Line | Count | Source | 51 | 45 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIfE9incrementEf Line | Count | Source | 51 | 9 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIdE9incrementEd Line | Count | Source | 51 | 259 | void increment(Ty key) { _nums.push_back(key); } |
|
52 | | |
53 | 5 | void increment_batch(const vectorized::PaddedPODArray<Ty>& keys) { |
54 | 5 | _nums.insert(keys.begin(), keys.end()); |
55 | 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 | 53 | 5 | void increment_batch(const vectorized::PaddedPODArray<Ty>& keys) { | 54 | 5 | _nums.insert(keys.begin(), keys.end()); | 55 | 5 | } |
Unexecuted instantiation: _ZN5doris6CountsInE15increment_batchERKNS_10vectorized8PODArrayInLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIfE15increment_batchERKNS_10vectorized8PODArrayIfLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE Unexecuted instantiation: _ZN5doris6CountsIdE15increment_batchERKNS_10vectorized8PODArrayIdLm4096ENS_9AllocatorILb0ELb0ELb0ENS_22DefaultMemoryAllocatorELb0EEELm16ELm15EEE |
56 | | |
57 | 1.71k | void serialize(vectorized::BufferWritable& buf) { |
58 | 1.71k | if (!_nums.empty()) { |
59 | 1.42k | pdqsort(_nums.begin(), _nums.end()); |
60 | 1.42k | size_t size = _nums.size(); |
61 | 1.42k | buf.write_binary(size); |
62 | 1.42k | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); |
63 | 1.42k | } else { |
64 | | // convert _sorted_nums_vec to _nums and do seiralize again |
65 | 292 | _convert_sorted_num_vec_to_nums(); |
66 | 292 | serialize(buf); |
67 | 292 | } |
68 | 1.71k | } _ZN5doris6CountsIaE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 4 | void serialize(vectorized::BufferWritable& buf) { | 58 | 4 | if (!_nums.empty()) { | 59 | 4 | pdqsort(_nums.begin(), _nums.end()); | 60 | 4 | size_t size = _nums.size(); | 61 | 4 | buf.write_binary(size); | 62 | 4 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 4 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 0 | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 4 | } |
_ZN5doris6CountsIsE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 16 | void serialize(vectorized::BufferWritable& buf) { | 58 | 16 | if (!_nums.empty()) { | 59 | 16 | pdqsort(_nums.begin(), _nums.end()); | 60 | 16 | size_t size = _nums.size(); | 61 | 16 | buf.write_binary(size); | 62 | 16 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 16 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 0 | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 16 | } |
_ZN5doris6CountsIiE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 1.10k | void serialize(vectorized::BufferWritable& buf) { | 58 | 1.10k | if (!_nums.empty()) { | 59 | 953 | pdqsort(_nums.begin(), _nums.end()); | 60 | 953 | size_t size = _nums.size(); | 61 | 953 | buf.write_binary(size); | 62 | 953 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 953 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 156 | _convert_sorted_num_vec_to_nums(); | 66 | 156 | serialize(buf); | 67 | 156 | } | 68 | 1.10k | } |
_ZN5doris6CountsIlE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 492 | void serialize(vectorized::BufferWritable& buf) { | 58 | 492 | if (!_nums.empty()) { | 59 | 356 | pdqsort(_nums.begin(), _nums.end()); | 60 | 356 | size_t size = _nums.size(); | 61 | 356 | buf.write_binary(size); | 62 | 356 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 356 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 136 | _convert_sorted_num_vec_to_nums(); | 66 | 136 | serialize(buf); | 67 | 136 | } | 68 | 492 | } |
_ZN5doris6CountsInE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 4 | void serialize(vectorized::BufferWritable& buf) { | 58 | 4 | if (!_nums.empty()) { | 59 | 4 | pdqsort(_nums.begin(), _nums.end()); | 60 | 4 | size_t size = _nums.size(); | 61 | 4 | buf.write_binary(size); | 62 | 4 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 4 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 0 | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 4 | } |
_ZN5doris6CountsIfE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 4 | void serialize(vectorized::BufferWritable& buf) { | 58 | 4 | if (!_nums.empty()) { | 59 | 4 | pdqsort(_nums.begin(), _nums.end()); | 60 | 4 | size_t size = _nums.size(); | 61 | 4 | buf.write_binary(size); | 62 | 4 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 4 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 0 | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 4 | } |
_ZN5doris6CountsIdE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 90 | void serialize(vectorized::BufferWritable& buf) { | 58 | 90 | if (!_nums.empty()) { | 59 | 90 | pdqsort(_nums.begin(), _nums.end()); | 60 | 90 | size_t size = _nums.size(); | 61 | 90 | buf.write_binary(size); | 62 | 90 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 90 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 0 | _convert_sorted_num_vec_to_nums(); | 66 | 0 | serialize(buf); | 67 | 0 | } | 68 | 90 | } |
|
69 | | |
70 | 1.30k | void unserialize(vectorized::BufferReadable& buf) { |
71 | 1.30k | size_t size; |
72 | 1.30k | buf.read_binary(size); |
73 | 1.30k | _nums.resize(size); |
74 | 1.30k | auto buff = buf.read(sizeof(Ty) * size); |
75 | 1.30k | memcpy(_nums.data(), buff.data, buff.size); |
76 | 1.30k | } _ZN5doris6CountsIaE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 4 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 4 | size_t size; | 72 | 4 | buf.read_binary(size); | 73 | 4 | _nums.resize(size); | 74 | 4 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 4 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 4 | } |
_ZN5doris6CountsIsE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 16 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 16 | size_t size; | 72 | 16 | buf.read_binary(size); | 73 | 16 | _nums.resize(size); | 74 | 16 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 16 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 16 | } |
_ZN5doris6CountsIiE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 836 | void unserialize(vectorized::BufferReadable& buf) { | 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 | } |
_ZN5doris6CountsIlE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 355 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 355 | size_t size; | 72 | 355 | buf.read_binary(size); | 73 | 355 | _nums.resize(size); | 74 | 355 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 355 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 355 | } |
_ZN5doris6CountsInE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 4 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 4 | size_t size; | 72 | 4 | buf.read_binary(size); | 73 | 4 | _nums.resize(size); | 74 | 4 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 4 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 4 | } |
_ZN5doris6CountsIfE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 4 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 4 | size_t size; | 72 | 4 | buf.read_binary(size); | 73 | 4 | _nums.resize(size); | 74 | 4 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 4 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 4 | } |
_ZN5doris6CountsIdE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 90 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 90 | size_t size; | 72 | 90 | buf.read_binary(size); | 73 | 90 | _nums.resize(size); | 74 | 90 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 90 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 90 | } |
|
77 | | |
78 | 1.10k | double terminate(double quantile) { |
79 | 1.10k | if (_sorted_nums_vec.size() <= 1) { |
80 | 952 | if (_sorted_nums_vec.size() == 1) { |
81 | 299 | _nums = std::move(_sorted_nums_vec[0]); |
82 | 299 | } |
83 | | |
84 | 952 | if (_nums.empty()) { |
85 | | // 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 | 0 | return 0.0; |
88 | 0 | } |
89 | | |
90 | 952 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { |
91 | 180 | pdqsort(_nums.begin(), _nums.end()); |
92 | 180 | } |
93 | | |
94 | 952 | if (quantile == 1 || _nums.size() == 1) { |
95 | 473 | return _nums.back(); |
96 | 473 | } |
97 | | |
98 | 479 | double u = (_nums.size() - 1) * quantile; |
99 | 479 | auto index = static_cast<uint32_t>(u); |
100 | 479 | return _nums[index] + |
101 | 479 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - |
102 | 479 | static_cast<double>(_nums[index])); |
103 | 952 | } else { |
104 | 153 | DCHECK(_nums.empty()); |
105 | 153 | size_t rows = 0; |
106 | 425 | for (const auto& i : _sorted_nums_vec) { |
107 | 425 | rows += i.size(); |
108 | 425 | } |
109 | 153 | const bool reverse = quantile > 0.5 && rows > 2; |
110 | 153 | double u = (rows - 1) * quantile; |
111 | 153 | auto index = static_cast<uint32_t>(u); |
112 | | // 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 | 153 | size_t target = reverse ? rows - index - 2 : index; |
120 | 153 | if (quantile == 1) { |
121 | 0 | target = 0; |
122 | 0 | } |
123 | 153 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); |
124 | 153 | if (quantile == 1) { |
125 | 0 | return second_number; |
126 | 0 | } |
127 | 153 | return first_number + |
128 | 153 | (u - static_cast<double>(index)) * |
129 | 153 | (static_cast<double>(second_number) - static_cast<double>(first_number)); |
130 | 153 | } |
131 | 1.10k | } _ZN5doris6CountsIaE9terminateEd Line | Count | Source | 78 | 61 | double terminate(double quantile) { | 79 | 61 | if (_sorted_nums_vec.size() <= 1) { | 80 | 60 | if (_sorted_nums_vec.size() == 1) { | 81 | 2 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 2 | } | 83 | | | 84 | 60 | if (_nums.empty()) { | 85 | | // 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 | 0 | return 0.0; | 88 | 0 | } | 89 | | | 90 | 60 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 24 | pdqsort(_nums.begin(), _nums.end()); | 92 | 24 | } | 93 | | | 94 | 60 | if (quantile == 1 || _nums.size() == 1) { | 95 | 34 | return _nums.back(); | 96 | 34 | } | 97 | | | 98 | 26 | double u = (_nums.size() - 1) * quantile; | 99 | 26 | auto index = static_cast<uint32_t>(u); | 100 | 26 | return _nums[index] + | 101 | 26 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 26 | static_cast<double>(_nums[index])); | 103 | 60 | } else { | 104 | 1 | DCHECK(_nums.empty()); | 105 | 1 | size_t rows = 0; | 106 | 2 | for (const auto& i : _sorted_nums_vec) { | 107 | 2 | rows += i.size(); | 108 | 2 | } | 109 | 1 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 1 | double u = (rows - 1) * quantile; | 111 | 1 | auto index = static_cast<uint32_t>(u); | 112 | | // 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 | 1 | size_t target = reverse ? rows - index - 2 : index; | 120 | 1 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 1 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 1 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 1 | return first_number + | 128 | 1 | (u - static_cast<double>(index)) * | 129 | 1 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 1 | } | 131 | 61 | } |
_ZN5doris6CountsIsE9terminateEd Line | Count | Source | 78 | 300 | double terminate(double quantile) { | 79 | 300 | if (_sorted_nums_vec.size() <= 1) { | 80 | 296 | if (_sorted_nums_vec.size() == 1) { | 81 | 2 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 2 | } | 83 | | | 84 | 296 | if (_nums.empty()) { | 85 | | // 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 | 0 | return 0.0; | 88 | 0 | } | 89 | | | 90 | 296 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 144 | pdqsort(_nums.begin(), _nums.end()); | 92 | 144 | } | 93 | | | 94 | 296 | if (quantile == 1 || _nums.size() == 1) { | 95 | 87 | return _nums.back(); | 96 | 87 | } | 97 | | | 98 | 209 | double u = (_nums.size() - 1) * quantile; | 99 | 209 | auto index = static_cast<uint32_t>(u); | 100 | 209 | return _nums[index] + | 101 | 209 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 209 | static_cast<double>(_nums[index])); | 103 | 296 | } else { | 104 | 4 | DCHECK(_nums.empty()); | 105 | 4 | size_t rows = 0; | 106 | 14 | for (const auto& i : _sorted_nums_vec) { | 107 | 14 | rows += i.size(); | 108 | 14 | } | 109 | 4 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 4 | double u = (rows - 1) * quantile; | 111 | 4 | auto index = static_cast<uint32_t>(u); | 112 | | // 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 | 4 | size_t target = reverse ? rows - index - 2 : index; | 120 | 4 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 4 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 4 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 4 | return first_number + | 128 | 4 | (u - static_cast<double>(index)) * | 129 | 4 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 4 | } | 131 | 300 | } |
_ZN5doris6CountsIiE9terminateEd Line | Count | Source | 78 | 444 | double terminate(double quantile) { | 79 | 444 | if (_sorted_nums_vec.size() <= 1) { | 80 | 346 | if (_sorted_nums_vec.size() == 1) { | 81 | 228 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 228 | } | 83 | | | 84 | 346 | if (_nums.empty()) { | 85 | | // 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 | 0 | return 0.0; | 88 | 0 | } | 89 | | | 90 | 346 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 11 | pdqsort(_nums.begin(), _nums.end()); | 92 | 11 | } | 93 | | | 94 | 346 | if (quantile == 1 || _nums.size() == 1) { | 95 | 239 | return _nums.back(); | 96 | 239 | } | 97 | | | 98 | 107 | double u = (_nums.size() - 1) * quantile; | 99 | 107 | auto index = static_cast<uint32_t>(u); | 100 | 107 | return _nums[index] + | 101 | 107 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 107 | static_cast<double>(_nums[index])); | 103 | 346 | } else { | 104 | 98 | DCHECK(_nums.empty()); | 105 | 98 | size_t rows = 0; | 106 | 269 | for (const auto& i : _sorted_nums_vec) { | 107 | 269 | rows += i.size(); | 108 | 269 | } | 109 | 98 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 98 | double u = (rows - 1) * quantile; | 111 | 98 | auto index = static_cast<uint32_t>(u); | 112 | | // 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 | 98 | size_t target = reverse ? rows - index - 2 : index; | 120 | 98 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 98 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 98 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 98 | return first_number + | 128 | 98 | (u - static_cast<double>(index)) * | 129 | 98 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 98 | } | 131 | 444 | } |
_ZN5doris6CountsIlE9terminateEd Line | Count | Source | 78 | 128 | double terminate(double quantile) { | 79 | 128 | if (_sorted_nums_vec.size() <= 1) { | 80 | 105 | if (_sorted_nums_vec.size() == 1) { | 81 | 35 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 35 | } | 83 | | | 84 | 105 | if (_nums.empty()) { | 85 | | // 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 | 0 | return 0.0; | 88 | 0 | } | 89 | | | 90 | 105 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 1 | pdqsort(_nums.begin(), _nums.end()); | 92 | 1 | } | 93 | | | 94 | 105 | if (quantile == 1 || _nums.size() == 1) { | 95 | 59 | return _nums.back(); | 96 | 59 | } | 97 | | | 98 | 46 | double u = (_nums.size() - 1) * quantile; | 99 | 46 | auto index = static_cast<uint32_t>(u); | 100 | 46 | return _nums[index] + | 101 | 46 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 46 | static_cast<double>(_nums[index])); | 103 | 105 | } else { | 104 | 23 | DCHECK(_nums.empty()); | 105 | 23 | size_t rows = 0; | 106 | 74 | for (const auto& i : _sorted_nums_vec) { | 107 | 74 | rows += i.size(); | 108 | 74 | } | 109 | 23 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 23 | double u = (rows - 1) * quantile; | 111 | 23 | auto index = static_cast<uint32_t>(u); | 112 | | // 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 | 23 | size_t target = reverse ? rows - index - 2 : index; | 120 | 23 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 23 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 23 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 23 | return first_number + | 128 | 23 | (u - static_cast<double>(index)) * | 129 | 23 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 23 | } | 131 | 128 | } |
_ZN5doris6CountsInE9terminateEd Line | Count | Source | 78 | 33 | double terminate(double quantile) { | 79 | 33 | if (_sorted_nums_vec.size() <= 1) { | 80 | 32 | if (_sorted_nums_vec.size() == 1) { | 81 | 2 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 2 | } | 83 | | | 84 | 32 | if (_nums.empty()) { | 85 | | // 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 | 0 | return 0.0; | 88 | 0 | } | 89 | | | 90 | 32 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 0 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | | | 94 | 32 | if (quantile == 1 || _nums.size() == 1) { | 95 | 24 | return _nums.back(); | 96 | 24 | } | 97 | | | 98 | 8 | double u = (_nums.size() - 1) * quantile; | 99 | 8 | auto index = static_cast<uint32_t>(u); | 100 | 8 | return _nums[index] + | 101 | 8 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 8 | static_cast<double>(_nums[index])); | 103 | 32 | } else { | 104 | 1 | DCHECK(_nums.empty()); | 105 | 1 | size_t rows = 0; | 106 | 2 | for (const auto& i : _sorted_nums_vec) { | 107 | 2 | rows += i.size(); | 108 | 2 | } | 109 | 1 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 1 | double u = (rows - 1) * quantile; | 111 | 1 | auto index = static_cast<uint32_t>(u); | 112 | | // 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 | 1 | size_t target = reverse ? rows - index - 2 : index; | 120 | 1 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 1 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 1 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 1 | return first_number + | 128 | 1 | (u - static_cast<double>(index)) * | 129 | 1 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 1 | } | 131 | 33 | } |
_ZN5doris6CountsIfE9terminateEd Line | Count | Source | 78 | 3 | double terminate(double quantile) { | 79 | 3 | if (_sorted_nums_vec.size() <= 1) { | 80 | 2 | if (_sorted_nums_vec.size() == 1) { | 81 | 2 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 2 | } | 83 | | | 84 | 2 | if (_nums.empty()) { | 85 | | // 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 | 0 | return 0.0; | 88 | 0 | } | 89 | | | 90 | 2 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 0 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | | | 94 | 2 | if (quantile == 1 || _nums.size() == 1) { | 95 | 0 | return _nums.back(); | 96 | 0 | } | 97 | | | 98 | 2 | double u = (_nums.size() - 1) * quantile; | 99 | 2 | auto index = static_cast<uint32_t>(u); | 100 | 2 | return _nums[index] + | 101 | 2 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 2 | static_cast<double>(_nums[index])); | 103 | 2 | } else { | 104 | 1 | DCHECK(_nums.empty()); | 105 | 1 | size_t rows = 0; | 106 | 2 | for (const auto& i : _sorted_nums_vec) { | 107 | 2 | rows += i.size(); | 108 | 2 | } | 109 | 1 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 1 | double u = (rows - 1) * quantile; | 111 | 1 | auto index = static_cast<uint32_t>(u); | 112 | | // 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 | 1 | size_t target = reverse ? rows - index - 2 : index; | 120 | 1 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 1 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 1 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 1 | return first_number + | 128 | 1 | (u - static_cast<double>(index)) * | 129 | 1 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 1 | } | 131 | 3 | } |
_ZN5doris6CountsIdE9terminateEd Line | Count | Source | 78 | 136 | double terminate(double quantile) { | 79 | 136 | if (_sorted_nums_vec.size() <= 1) { | 80 | 111 | if (_sorted_nums_vec.size() == 1) { | 81 | 28 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 28 | } | 83 | | | 84 | 111 | if (_nums.empty()) { | 85 | | // 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 | 0 | return 0.0; | 88 | 0 | } | 89 | | | 90 | 111 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 0 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | | | 94 | 111 | if (quantile == 1 || _nums.size() == 1) { | 95 | 30 | return _nums.back(); | 96 | 30 | } | 97 | | | 98 | 81 | double u = (_nums.size() - 1) * quantile; | 99 | 81 | auto index = static_cast<uint32_t>(u); | 100 | 81 | return _nums[index] + | 101 | 81 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 81 | static_cast<double>(_nums[index])); | 103 | 111 | } else { | 104 | 25 | DCHECK(_nums.empty()); | 105 | 25 | size_t rows = 0; | 106 | 62 | for (const auto& i : _sorted_nums_vec) { | 107 | 62 | rows += i.size(); | 108 | 62 | } | 109 | 25 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 25 | double u = (rows - 1) * quantile; | 111 | 25 | auto index = static_cast<uint32_t>(u); | 112 | | // 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 | 25 | size_t target = reverse ? rows - index - 2 : index; | 120 | 25 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 25 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 25 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 25 | return first_number + | 128 | 25 | (u - static_cast<double>(index)) * | 129 | 25 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 25 | } | 131 | 136 | } |
|
132 | | |
133 | | private: |
134 | | struct Node { |
135 | | Ty value; |
136 | | int array_index; |
137 | | int64_t element_index; |
138 | | |
139 | 1.51k | auto operator<=>(const Node& other) const { return value <=> other.value; }_ZNK5doris6CountsIaE4NodessERKS2_ Line | Count | Source | 139 | 2 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIsE4NodessERKS2_ Line | Count | Source | 139 | 70 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIiE4NodessERKS2_ Line | Count | Source | 139 | 935 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIlE4NodessERKS2_ Line | Count | Source | 139 | 421 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsInE4NodessERKS2_ Line | Count | Source | 139 | 2 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIfE4NodessERKS2_ Line | Count | Source | 139 | 2 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIdE4NodessERKS2_ Line | Count | Source | 139 | 80 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
|
140 | | }; |
141 | | |
142 | 292 | void _convert_sorted_num_vec_to_nums() { |
143 | 292 | size_t rows = 0; |
144 | 586 | for (const auto& i : _sorted_nums_vec) { |
145 | 586 | rows += i.size(); |
146 | 586 | } |
147 | 292 | _nums.resize(rows); |
148 | 292 | size_t count = 0; |
149 | | |
150 | 292 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
151 | 878 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
152 | 586 | if (!_sorted_nums_vec[i].empty()) { |
153 | 586 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
154 | 586 | } |
155 | 586 | } |
156 | | |
157 | 1.02k | while (!min_heap.empty()) { |
158 | 737 | Node node = min_heap.top(); |
159 | 737 | min_heap.pop(); |
160 | 737 | _nums[count++] = node.value; |
161 | 737 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
162 | 151 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
163 | 151 | min_heap.push(node); |
164 | 151 | } |
165 | 737 | } |
166 | 292 | _sorted_nums_vec.clear(); |
167 | 292 | } 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 | 142 | 156 | void _convert_sorted_num_vec_to_nums() { | 143 | 156 | size_t rows = 0; | 144 | 339 | for (const auto& i : _sorted_nums_vec) { | 145 | 339 | rows += i.size(); | 146 | 339 | } | 147 | 156 | _nums.resize(rows); | 148 | 156 | size_t count = 0; | 149 | | | 150 | 156 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 151 | 495 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 152 | 339 | if (!_sorted_nums_vec[i].empty()) { | 153 | 339 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 154 | 339 | } | 155 | 339 | } | 156 | | | 157 | 531 | while (!min_heap.empty()) { | 158 | 375 | 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 | 36 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 163 | 36 | min_heap.push(node); | 164 | 36 | } | 165 | 375 | } | 166 | 156 | _sorted_nums_vec.clear(); | 167 | 156 | } |
_ZN5doris6CountsIlE31_convert_sorted_num_vec_to_numsEv Line | Count | Source | 142 | 136 | void _convert_sorted_num_vec_to_nums() { | 143 | 136 | size_t rows = 0; | 144 | 247 | for (const auto& i : _sorted_nums_vec) { | 145 | 247 | rows += i.size(); | 146 | 247 | } | 147 | 136 | _nums.resize(rows); | 148 | 136 | size_t count = 0; | 149 | | | 150 | 136 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 151 | 383 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 152 | 247 | if (!_sorted_nums_vec[i].empty()) { | 153 | 247 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 154 | 247 | } | 155 | 247 | } | 156 | | | 157 | 498 | while (!min_heap.empty()) { | 158 | 362 | Node node = min_heap.top(); | 159 | 362 | min_heap.pop(); | 160 | 362 | _nums[count++] = node.value; | 161 | 362 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 162 | 115 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 163 | 115 | min_heap.push(node); | 164 | 115 | } | 165 | 362 | } | 166 | 136 | _sorted_nums_vec.clear(); | 167 | 136 | } |
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 |
168 | | |
169 | 153 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { |
170 | 153 | Ty first_number = 0, second_number = 0; |
171 | 153 | size_t count = 0; |
172 | 153 | if (reverse) { |
173 | 28 | std::priority_queue<Node> max_heap; |
174 | 122 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
175 | 94 | if (!_sorted_nums_vec[i].empty()) { |
176 | 94 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, |
177 | 94 | _sorted_nums_vec[i].size() - 1); |
178 | 94 | } |
179 | 94 | } |
180 | | |
181 | 113 | while (!max_heap.empty()) { |
182 | 113 | Node node = max_heap.top(); |
183 | 113 | max_heap.pop(); |
184 | 113 | if (count == target) { |
185 | 28 | second_number = node.value; |
186 | 85 | } else if (count == target + 1) { |
187 | 28 | first_number = node.value; |
188 | 28 | break; |
189 | 28 | } |
190 | 85 | ++count; |
191 | 85 | if (--node.element_index >= 0) { |
192 | 66 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
193 | 66 | max_heap.push(node); |
194 | 66 | } |
195 | 85 | } |
196 | | |
197 | 125 | } else { |
198 | 125 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
199 | 456 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
200 | 331 | if (!_sorted_nums_vec[i].empty()) { |
201 | 331 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
202 | 331 | } |
203 | 331 | } |
204 | | |
205 | 352 | while (!min_heap.empty()) { |
206 | 352 | Node node = min_heap.top(); |
207 | 352 | min_heap.pop(); |
208 | 352 | if (count == target) { |
209 | 125 | first_number = node.value; |
210 | 227 | } else if (count == target + 1) { |
211 | 125 | second_number = node.value; |
212 | 125 | break; |
213 | 125 | } |
214 | 227 | ++count; |
215 | 227 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
216 | 143 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
217 | 143 | min_heap.push(node); |
218 | 143 | } |
219 | 227 | } |
220 | 125 | } |
221 | | |
222 | 153 | return {first_number, second_number}; |
223 | 153 | } _ZN5doris6CountsIaE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 1 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 1 | Ty first_number = 0, second_number = 0; | 171 | 1 | size_t count = 0; | 172 | 1 | if (reverse) { | 173 | 0 | std::priority_queue<Node> max_heap; | 174 | 0 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 0 | if (!_sorted_nums_vec[i].empty()) { | 176 | 0 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 0 | _sorted_nums_vec[i].size() - 1); | 178 | 0 | } | 179 | 0 | } | 180 | |
| 181 | 0 | while (!max_heap.empty()) { | 182 | 0 | Node node = max_heap.top(); | 183 | 0 | max_heap.pop(); | 184 | 0 | if (count == target) { | 185 | 0 | second_number = node.value; | 186 | 0 | } else if (count == target + 1) { | 187 | 0 | first_number = node.value; | 188 | 0 | break; | 189 | 0 | } | 190 | 0 | ++count; | 191 | 0 | if (--node.element_index >= 0) { | 192 | 0 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 0 | max_heap.push(node); | 194 | 0 | } | 195 | 0 | } | 196 | |
| 197 | 1 | } else { | 198 | 1 | 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 | 2 | if (!_sorted_nums_vec[i].empty()) { | 201 | 2 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 2 | } | 203 | 2 | } | 204 | | | 205 | 3 | while (!min_heap.empty()) { | 206 | 3 | Node node = min_heap.top(); | 207 | 3 | min_heap.pop(); | 208 | 3 | if (count == target) { | 209 | 1 | first_number = node.value; | 210 | 2 | } else if (count == target + 1) { | 211 | 1 | second_number = node.value; | 212 | 1 | break; | 213 | 1 | } | 214 | 2 | ++count; | 215 | 2 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 1 | min_heap.push(node); | 218 | 1 | } | 219 | 2 | } | 220 | 1 | } | 221 | | | 222 | 1 | return {first_number, second_number}; | 223 | 1 | } |
_ZN5doris6CountsIsE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 4 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 4 | Ty first_number = 0, second_number = 0; | 171 | 4 | size_t count = 0; | 172 | 4 | if (reverse) { | 173 | 1 | std::priority_queue<Node> max_heap; | 174 | 5 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 4 | if (!_sorted_nums_vec[i].empty()) { | 176 | 4 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 4 | _sorted_nums_vec[i].size() - 1); | 178 | 4 | } | 179 | 4 | } | 180 | | | 181 | 6 | while (!max_heap.empty()) { | 182 | 6 | Node node = max_heap.top(); | 183 | 6 | max_heap.pop(); | 184 | 6 | if (count == target) { | 185 | 1 | second_number = node.value; | 186 | 5 | } else if (count == target + 1) { | 187 | 1 | first_number = node.value; | 188 | 1 | break; | 189 | 1 | } | 190 | 5 | ++count; | 191 | 5 | if (--node.element_index >= 0) { | 192 | 3 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 3 | max_heap.push(node); | 194 | 3 | } | 195 | 5 | } | 196 | | | 197 | 3 | } else { | 198 | 3 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 13 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 10 | if (!_sorted_nums_vec[i].empty()) { | 201 | 10 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 10 | } | 203 | 10 | } | 204 | | | 205 | 16 | while (!min_heap.empty()) { | 206 | 16 | Node node = min_heap.top(); | 207 | 16 | min_heap.pop(); | 208 | 16 | if (count == target) { | 209 | 3 | first_number = node.value; | 210 | 13 | } else if (count == target + 1) { | 211 | 3 | second_number = node.value; | 212 | 3 | break; | 213 | 3 | } | 214 | 13 | ++count; | 215 | 13 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 12 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 12 | min_heap.push(node); | 218 | 12 | } | 219 | 13 | } | 220 | 3 | } | 221 | | | 222 | 4 | return {first_number, second_number}; | 223 | 4 | } |
_ZN5doris6CountsIiE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 98 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 98 | Ty first_number = 0, second_number = 0; | 171 | 98 | size_t count = 0; | 172 | 98 | if (reverse) { | 173 | 10 | std::priority_queue<Node> max_heap; | 174 | 38 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 28 | if (!_sorted_nums_vec[i].empty()) { | 176 | 28 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 28 | _sorted_nums_vec[i].size() - 1); | 178 | 28 | } | 179 | 28 | } | 180 | | | 181 | 39 | while (!max_heap.empty()) { | 182 | 39 | Node node = max_heap.top(); | 183 | 39 | max_heap.pop(); | 184 | 39 | if (count == target) { | 185 | 10 | second_number = node.value; | 186 | 29 | } else if (count == target + 1) { | 187 | 10 | first_number = node.value; | 188 | 10 | break; | 189 | 10 | } | 190 | 29 | ++count; | 191 | 29 | if (--node.element_index >= 0) { | 192 | 22 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 22 | max_heap.push(node); | 194 | 22 | } | 195 | 29 | } | 196 | | | 197 | 88 | } else { | 198 | 88 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 329 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 241 | if (!_sorted_nums_vec[i].empty()) { | 201 | 241 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 241 | } | 203 | 241 | } | 204 | | | 205 | 247 | while (!min_heap.empty()) { | 206 | 247 | Node node = min_heap.top(); | 207 | 247 | min_heap.pop(); | 208 | 247 | if (count == target) { | 209 | 88 | first_number = node.value; | 210 | 159 | } else if (count == target + 1) { | 211 | 88 | second_number = node.value; | 212 | 88 | break; | 213 | 88 | } | 214 | 159 | ++count; | 215 | 159 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 99 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 99 | min_heap.push(node); | 218 | 99 | } | 219 | 159 | } | 220 | 88 | } | 221 | | | 222 | 98 | return {first_number, second_number}; | 223 | 98 | } |
_ZN5doris6CountsIlE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 23 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 23 | Ty first_number = 0, second_number = 0; | 171 | 23 | size_t count = 0; | 172 | 23 | if (reverse) { | 173 | 15 | std::priority_queue<Node> max_heap; | 174 | 71 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 56 | if (!_sorted_nums_vec[i].empty()) { | 176 | 56 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 56 | _sorted_nums_vec[i].size() - 1); | 178 | 56 | } | 179 | 56 | } | 180 | | | 181 | 63 | while (!max_heap.empty()) { | 182 | 63 | Node node = max_heap.top(); | 183 | 63 | max_heap.pop(); | 184 | 63 | if (count == target) { | 185 | 15 | second_number = node.value; | 186 | 48 | } else if (count == target + 1) { | 187 | 15 | first_number = node.value; | 188 | 15 | break; | 189 | 15 | } | 190 | 48 | ++count; | 191 | 48 | if (--node.element_index >= 0) { | 192 | 39 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 39 | max_heap.push(node); | 194 | 39 | } | 195 | 48 | } | 196 | | | 197 | 15 | } else { | 198 | 8 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 26 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 18 | if (!_sorted_nums_vec[i].empty()) { | 201 | 18 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 18 | } | 203 | 18 | } | 204 | | | 205 | 25 | while (!min_heap.empty()) { | 206 | 25 | Node node = min_heap.top(); | 207 | 25 | min_heap.pop(); | 208 | 25 | if (count == target) { | 209 | 8 | first_number = node.value; | 210 | 17 | } else if (count == target + 1) { | 211 | 8 | second_number = node.value; | 212 | 8 | break; | 213 | 8 | } | 214 | 17 | ++count; | 215 | 17 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 15 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 15 | min_heap.push(node); | 218 | 15 | } | 219 | 17 | } | 220 | 8 | } | 221 | | | 222 | 23 | return {first_number, second_number}; | 223 | 23 | } |
_ZN5doris6CountsInE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 1 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 1 | Ty first_number = 0, second_number = 0; | 171 | 1 | size_t count = 0; | 172 | 1 | if (reverse) { | 173 | 0 | std::priority_queue<Node> max_heap; | 174 | 0 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 0 | if (!_sorted_nums_vec[i].empty()) { | 176 | 0 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 0 | _sorted_nums_vec[i].size() - 1); | 178 | 0 | } | 179 | 0 | } | 180 | |
| 181 | 0 | while (!max_heap.empty()) { | 182 | 0 | Node node = max_heap.top(); | 183 | 0 | max_heap.pop(); | 184 | 0 | if (count == target) { | 185 | 0 | second_number = node.value; | 186 | 0 | } else if (count == target + 1) { | 187 | 0 | first_number = node.value; | 188 | 0 | break; | 189 | 0 | } | 190 | 0 | ++count; | 191 | 0 | if (--node.element_index >= 0) { | 192 | 0 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 0 | max_heap.push(node); | 194 | 0 | } | 195 | 0 | } | 196 | |
| 197 | 1 | } else { | 198 | 1 | 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 | 2 | if (!_sorted_nums_vec[i].empty()) { | 201 | 2 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 2 | } | 203 | 2 | } | 204 | | | 205 | 3 | while (!min_heap.empty()) { | 206 | 3 | Node node = min_heap.top(); | 207 | 3 | min_heap.pop(); | 208 | 3 | if (count == target) { | 209 | 1 | first_number = node.value; | 210 | 2 | } else if (count == target + 1) { | 211 | 1 | second_number = node.value; | 212 | 1 | break; | 213 | 1 | } | 214 | 2 | ++count; | 215 | 2 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 1 | min_heap.push(node); | 218 | 1 | } | 219 | 2 | } | 220 | 1 | } | 221 | | | 222 | 1 | return {first_number, second_number}; | 223 | 1 | } |
_ZN5doris6CountsIfE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 1 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 1 | Ty first_number = 0, second_number = 0; | 171 | 1 | size_t count = 0; | 172 | 1 | if (reverse) { | 173 | 0 | std::priority_queue<Node> max_heap; | 174 | 0 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 0 | if (!_sorted_nums_vec[i].empty()) { | 176 | 0 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 0 | _sorted_nums_vec[i].size() - 1); | 178 | 0 | } | 179 | 0 | } | 180 | |
| 181 | 0 | while (!max_heap.empty()) { | 182 | 0 | Node node = max_heap.top(); | 183 | 0 | max_heap.pop(); | 184 | 0 | if (count == target) { | 185 | 0 | second_number = node.value; | 186 | 0 | } else if (count == target + 1) { | 187 | 0 | first_number = node.value; | 188 | 0 | break; | 189 | 0 | } | 190 | 0 | ++count; | 191 | 0 | if (--node.element_index >= 0) { | 192 | 0 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 0 | max_heap.push(node); | 194 | 0 | } | 195 | 0 | } | 196 | |
| 197 | 1 | } else { | 198 | 1 | 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 | 2 | if (!_sorted_nums_vec[i].empty()) { | 201 | 2 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 2 | } | 203 | 2 | } | 204 | | | 205 | 3 | while (!min_heap.empty()) { | 206 | 3 | Node node = min_heap.top(); | 207 | 3 | min_heap.pop(); | 208 | 3 | if (count == target) { | 209 | 1 | first_number = node.value; | 210 | 2 | } else if (count == target + 1) { | 211 | 1 | second_number = node.value; | 212 | 1 | break; | 213 | 1 | } | 214 | 2 | ++count; | 215 | 2 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 1 | min_heap.push(node); | 218 | 1 | } | 219 | 2 | } | 220 | 1 | } | 221 | | | 222 | 1 | return {first_number, second_number}; | 223 | 1 | } |
_ZN5doris6CountsIdE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 25 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 25 | Ty first_number = 0, second_number = 0; | 171 | 25 | size_t count = 0; | 172 | 25 | if (reverse) { | 173 | 2 | std::priority_queue<Node> max_heap; | 174 | 8 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 6 | if (!_sorted_nums_vec[i].empty()) { | 176 | 6 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 6 | _sorted_nums_vec[i].size() - 1); | 178 | 6 | } | 179 | 6 | } | 180 | | | 181 | 5 | while (!max_heap.empty()) { | 182 | 5 | Node node = max_heap.top(); | 183 | 5 | max_heap.pop(); | 184 | 5 | if (count == target) { | 185 | 2 | second_number = node.value; | 186 | 3 | } else if (count == target + 1) { | 187 | 2 | first_number = node.value; | 188 | 2 | break; | 189 | 2 | } | 190 | 3 | ++count; | 191 | 3 | if (--node.element_index >= 0) { | 192 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 2 | max_heap.push(node); | 194 | 2 | } | 195 | 3 | } | 196 | | | 197 | 23 | } else { | 198 | 23 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 79 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 56 | if (!_sorted_nums_vec[i].empty()) { | 201 | 56 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 56 | } | 203 | 56 | } | 204 | | | 205 | 55 | while (!min_heap.empty()) { | 206 | 55 | Node node = min_heap.top(); | 207 | 55 | min_heap.pop(); | 208 | 55 | if (count == target) { | 209 | 23 | first_number = node.value; | 210 | 32 | } else if (count == target + 1) { | 211 | 23 | second_number = node.value; | 212 | 23 | break; | 213 | 23 | } | 214 | 32 | ++count; | 215 | 32 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 14 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 14 | min_heap.push(node); | 218 | 14 | } | 219 | 32 | } | 220 | 23 | } | 221 | | | 222 | 25 | return {first_number, second_number}; | 223 | 25 | } |
|
224 | | |
225 | | vectorized::PODArray<Ty> _nums; |
226 | | std::vector<vectorized::PODArray<Ty>> _sorted_nums_vec; |
227 | | }; |
228 | | |
229 | | } // namespace doris |