/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 | 49 | Counts() = default; |
Line | Count | Source | 35 | 207 | Counts() = default; |
Line | Count | Source | 35 | 2.23k | Counts() = default; |
Line | Count | Source | 35 | 841 | Counts() = default; |
Line | Count | Source | 35 | 45 | Counts() = default; |
Line | Count | Source | 35 | 15 | Counts() = default; |
Line | Count | Source | 35 | 270 | Counts() = default; |
|
36 | | |
37 | 1.31k | void merge(Counts* other) { |
38 | 1.31k | if (other != nullptr && !other->_nums.empty()) { |
39 | 1.31k | _sorted_nums_vec.emplace_back(std::move(other->_nums)); |
40 | 1.31k | } |
41 | 1.31k | } _ZN5doris6CountsIaE5mergeEPS1_ Line | Count | Source | 37 | 6 | void merge(Counts* other) { | 38 | 6 | if (other != nullptr && !other->_nums.empty()) { | 39 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 6 | } | 41 | 6 | } |
_ZN5doris6CountsIsE5mergeEPS1_ Line | Count | Source | 37 | 12 | void merge(Counts* other) { | 38 | 12 | if (other != nullptr && !other->_nums.empty()) { | 39 | 12 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 12 | } | 41 | 12 | } |
_ZN5doris6CountsIiE5mergeEPS1_ Line | Count | Source | 37 | 838 | void merge(Counts* other) { | 38 | 838 | if (other != nullptr && !other->_nums.empty()) { | 39 | 838 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 838 | } | 41 | 838 | } |
_ZN5doris6CountsIlE5mergeEPS1_ Line | Count | Source | 37 | 353 | void merge(Counts* other) { | 38 | 353 | if (other != nullptr && !other->_nums.empty()) { | 39 | 353 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 353 | } | 41 | 353 | } |
_ZN5doris6CountsInE5mergeEPS1_ Line | Count | Source | 37 | 6 | void merge(Counts* other) { | 38 | 6 | if (other != nullptr && !other->_nums.empty()) { | 39 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 6 | } | 41 | 6 | } |
_ZN5doris6CountsIfE5mergeEPS1_ Line | Count | Source | 37 | 6 | void merge(Counts* other) { | 38 | 6 | if (other != nullptr && !other->_nums.empty()) { | 39 | 6 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 6 | } | 41 | 6 | } |
_ZN5doris6CountsIdE5mergeEPS1_ Line | Count | Source | 37 | 92 | void merge(Counts* other) { | 38 | 92 | if (other != nullptr && !other->_nums.empty()) { | 39 | 92 | _sorted_nums_vec.emplace_back(std::move(other->_nums)); | 40 | 92 | } | 41 | 92 | } |
|
42 | | |
43 | | void increment(Ty key, uint32_t i) { |
44 | | auto old_size = _nums.size(); |
45 | | _nums.resize(_nums.size() + i); |
46 | | for (uint32_t j = 0; j < i; ++j) { |
47 | | _nums[old_size + j] = key; |
48 | | } |
49 | | } |
50 | | |
51 | 2.93k | void increment(Ty key) { _nums.push_back(key); }_ZN5doris6CountsIaE9incrementEa Line | Count | Source | 51 | 73 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIsE9incrementEs Line | Count | Source | 51 | 552 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIiE9incrementEi Line | Count | Source | 51 | 1.59k | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIlE9incrementEl Line | Count | Source | 51 | 401 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsInE9incrementEn Line | Count | Source | 51 | 45 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIfE9incrementEf Line | Count | Source | 51 | 9 | void increment(Ty key) { _nums.push_back(key); } |
_ZN5doris6CountsIdE9incrementEd Line | Count | Source | 51 | 259 | void increment(Ty key) { _nums.push_back(key); } |
|
52 | | |
53 | 5 | void increment_batch(const 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.72k | void serialize(vectorized::BufferWritable& buf) { |
58 | 1.72k | if (!_nums.empty()) { |
59 | 1.43k | pdqsort(_nums.begin(), _nums.end()); |
60 | 1.43k | size_t size = _nums.size(); |
61 | 1.43k | buf.write_binary(size); |
62 | 1.43k | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); |
63 | 1.43k | } else { |
64 | | // convert _sorted_nums_vec to _nums and do seiralize again |
65 | 299 | _convert_sorted_num_vec_to_nums(); |
66 | 299 | serialize(buf); |
67 | 299 | } |
68 | 1.72k | } _ZN5doris6CountsIaE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 6 | void serialize(vectorized::BufferWritable& buf) { | 58 | 6 | if (!_nums.empty()) { | 59 | 6 | pdqsort(_nums.begin(), _nums.end()); | 60 | 6 | size_t size = _nums.size(); | 61 | 6 | buf.write_binary(size); | 62 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 6 | } 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 | 6 | } |
_ZN5doris6CountsIsE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 12 | void serialize(vectorized::BufferWritable& buf) { | 58 | 12 | if (!_nums.empty()) { | 59 | 12 | pdqsort(_nums.begin(), _nums.end()); | 60 | 12 | size_t size = _nums.size(); | 61 | 12 | buf.write_binary(size); | 62 | 12 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 12 | } 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 | 12 | } |
_ZN5doris6CountsIiE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 1.11k | void serialize(vectorized::BufferWritable& buf) { | 58 | 1.11k | if (!_nums.empty()) { | 59 | 955 | pdqsort(_nums.begin(), _nums.end()); | 60 | 955 | size_t size = _nums.size(); | 61 | 955 | buf.write_binary(size); | 62 | 955 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 955 | } 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.11k | } |
_ZN5doris6CountsIlE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 496 | void serialize(vectorized::BufferWritable& buf) { | 58 | 496 | if (!_nums.empty()) { | 59 | 353 | pdqsort(_nums.begin(), _nums.end()); | 60 | 353 | size_t size = _nums.size(); | 61 | 353 | buf.write_binary(size); | 62 | 353 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 353 | } else { | 64 | | // convert _sorted_nums_vec to _nums and do seiralize again | 65 | 143 | _convert_sorted_num_vec_to_nums(); | 66 | 143 | serialize(buf); | 67 | 143 | } | 68 | 496 | } |
_ZN5doris6CountsInE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 6 | void serialize(vectorized::BufferWritable& buf) { | 58 | 6 | if (!_nums.empty()) { | 59 | 6 | pdqsort(_nums.begin(), _nums.end()); | 60 | 6 | size_t size = _nums.size(); | 61 | 6 | buf.write_binary(size); | 62 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 6 | } 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 | 6 | } |
_ZN5doris6CountsIfE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 6 | void serialize(vectorized::BufferWritable& buf) { | 58 | 6 | if (!_nums.empty()) { | 59 | 6 | pdqsort(_nums.begin(), _nums.end()); | 60 | 6 | size_t size = _nums.size(); | 61 | 6 | buf.write_binary(size); | 62 | 6 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 6 | } 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 | 6 | } |
_ZN5doris6CountsIdE9serializeERNS_10vectorized14BufferWritableE Line | Count | Source | 57 | 92 | void serialize(vectorized::BufferWritable& buf) { | 58 | 92 | if (!_nums.empty()) { | 59 | 92 | pdqsort(_nums.begin(), _nums.end()); | 60 | 92 | size_t size = _nums.size(); | 61 | 92 | buf.write_binary(size); | 62 | 92 | buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size); | 63 | 92 | } 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 | 92 | } |
|
69 | | |
70 | 1.31k | void unserialize(vectorized::BufferReadable& buf) { |
71 | 1.31k | size_t size; |
72 | 1.31k | buf.read_binary(size); |
73 | 1.31k | _nums.resize(size); |
74 | 1.31k | auto buff = buf.read(sizeof(Ty) * size); |
75 | 1.31k | memcpy(_nums.data(), buff.data, buff.size); |
76 | 1.31k | } _ZN5doris6CountsIaE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 6 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 6 | size_t size; | 72 | 6 | buf.read_binary(size); | 73 | 6 | _nums.resize(size); | 74 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 6 | } |
_ZN5doris6CountsIsE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 12 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 12 | size_t size; | 72 | 12 | buf.read_binary(size); | 73 | 12 | _nums.resize(size); | 74 | 12 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 12 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 12 | } |
_ZN5doris6CountsIiE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 838 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 838 | size_t size; | 72 | 838 | buf.read_binary(size); | 73 | 838 | _nums.resize(size); | 74 | 838 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 838 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 838 | } |
_ZN5doris6CountsIlE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 353 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 353 | size_t size; | 72 | 353 | buf.read_binary(size); | 73 | 353 | _nums.resize(size); | 74 | 353 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 353 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 353 | } |
_ZN5doris6CountsInE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 6 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 6 | size_t size; | 72 | 6 | buf.read_binary(size); | 73 | 6 | _nums.resize(size); | 74 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 6 | } |
_ZN5doris6CountsIfE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 6 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 6 | size_t size; | 72 | 6 | buf.read_binary(size); | 73 | 6 | _nums.resize(size); | 74 | 6 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 6 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 6 | } |
_ZN5doris6CountsIdE11unserializeERNS_10vectorized14BufferReadableE Line | Count | Source | 70 | 92 | void unserialize(vectorized::BufferReadable& buf) { | 71 | 92 | size_t size; | 72 | 92 | buf.read_binary(size); | 73 | 92 | _nums.resize(size); | 74 | 92 | auto buff = buf.read(sizeof(Ty) * size); | 75 | 92 | memcpy(_nums.data(), buff.data, buff.size); | 76 | 92 | } |
|
77 | | |
78 | 1.10k | double terminate(double quantile) { |
79 | 1.10k | if (_sorted_nums_vec.size() <= 1) { |
80 | 942 | if (_sorted_nums_vec.size() == 1) { |
81 | 289 | _nums = std::move(_sorted_nums_vec[0]); |
82 | 289 | } |
83 | | |
84 | 942 | 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 | 942 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { |
91 | 180 | pdqsort(_nums.begin(), _nums.end()); |
92 | 180 | } |
93 | | |
94 | 942 | if (quantile == 1 || _nums.size() == 1) { |
95 | 473 | return _nums.back(); |
96 | 473 | } |
97 | | |
98 | 469 | double u = (_nums.size() - 1) * quantile; |
99 | 469 | auto index = static_cast<uint32_t>(u); |
100 | 469 | return _nums[index] + |
101 | 469 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - |
102 | 469 | static_cast<double>(_nums[index])); |
103 | 942 | } else { |
104 | 163 | DCHECK(_nums.empty()); |
105 | 163 | size_t rows = 0; |
106 | 428 | for (const auto& i : _sorted_nums_vec) { |
107 | 428 | rows += i.size(); |
108 | 428 | } |
109 | 163 | const bool reverse = quantile > 0.5 && rows > 2; |
110 | 163 | double u = (rows - 1) * quantile; |
111 | 163 | 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 | 163 | size_t target = reverse ? rows - index - 2 : index; |
120 | 163 | if (quantile == 1) { |
121 | 0 | target = 0; |
122 | 0 | } |
123 | 163 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); |
124 | 163 | if (quantile == 1) { |
125 | 0 | return second_number; |
126 | 0 | } |
127 | 163 | return first_number + |
128 | 163 | (u - static_cast<double>(index)) * |
129 | 163 | (static_cast<double>(second_number) - static_cast<double>(first_number)); |
130 | 163 | } |
131 | 1.10k | } _ZN5doris6CountsIaE9terminateEd Line | Count | Source | 78 | 61 | double terminate(double quantile) { | 79 | 61 | if (_sorted_nums_vec.size() <= 1) { | 80 | 58 | if (_sorted_nums_vec.size() == 1) { | 81 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 0 | } | 83 | | | 84 | 58 | 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 | 58 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 24 | pdqsort(_nums.begin(), _nums.end()); | 92 | 24 | } | 93 | | | 94 | 58 | if (quantile == 1 || _nums.size() == 1) { | 95 | 34 | return _nums.back(); | 96 | 34 | } | 97 | | | 98 | 24 | double u = (_nums.size() - 1) * quantile; | 99 | 24 | auto index = static_cast<uint32_t>(u); | 100 | 24 | return _nums[index] + | 101 | 24 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 24 | static_cast<double>(_nums[index])); | 103 | 58 | } else { | 104 | 3 | DCHECK(_nums.empty()); | 105 | 3 | size_t rows = 0; | 106 | 6 | for (const auto& i : _sorted_nums_vec) { | 107 | 6 | rows += i.size(); | 108 | 6 | } | 109 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 3 | double u = (rows - 1) * quantile; | 111 | 3 | 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 | 3 | size_t target = reverse ? rows - index - 2 : index; | 120 | 3 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 3 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 3 | return first_number + | 128 | 3 | (u - static_cast<double>(index)) * | 129 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 3 | } | 131 | 61 | } |
_ZN5doris6CountsIsE9terminateEd Line | Count | Source | 78 | 300 | double terminate(double quantile) { | 79 | 300 | if (_sorted_nums_vec.size() <= 1) { | 80 | 294 | if (_sorted_nums_vec.size() == 1) { | 81 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 0 | } | 83 | | | 84 | 294 | 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 | 294 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 144 | pdqsort(_nums.begin(), _nums.end()); | 92 | 144 | } | 93 | | | 94 | 294 | if (quantile == 1 || _nums.size() == 1) { | 95 | 87 | return _nums.back(); | 96 | 87 | } | 97 | | | 98 | 207 | double u = (_nums.size() - 1) * quantile; | 99 | 207 | auto index = static_cast<uint32_t>(u); | 100 | 207 | return _nums[index] + | 101 | 207 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 207 | static_cast<double>(_nums[index])); | 103 | 294 | } else { | 104 | 6 | DCHECK(_nums.empty()); | 105 | 6 | size_t rows = 0; | 106 | 12 | for (const auto& i : _sorted_nums_vec) { | 107 | 12 | rows += i.size(); | 108 | 12 | } | 109 | 6 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 6 | double u = (rows - 1) * quantile; | 111 | 6 | 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 | 6 | size_t target = reverse ? rows - index - 2 : index; | 120 | 6 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 6 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 6 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 6 | return first_number + | 128 | 6 | (u - static_cast<double>(index)) * | 129 | 6 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 6 | } | 131 | 300 | } |
_ZN5doris6CountsIiE9terminateEd Line | Count | Source | 78 | 444 | double terminate(double quantile) { | 79 | 444 | if (_sorted_nums_vec.size() <= 1) { | 80 | 344 | if (_sorted_nums_vec.size() == 1) { | 81 | 226 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 226 | } | 83 | | | 84 | 344 | 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 | 344 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 11 | pdqsort(_nums.begin(), _nums.end()); | 92 | 11 | } | 93 | | | 94 | 344 | if (quantile == 1 || _nums.size() == 1) { | 95 | 239 | return _nums.back(); | 96 | 239 | } | 97 | | | 98 | 105 | double u = (_nums.size() - 1) * quantile; | 99 | 105 | auto index = static_cast<uint32_t>(u); | 100 | 105 | return _nums[index] + | 101 | 105 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 105 | static_cast<double>(_nums[index])); | 103 | 344 | } else { | 104 | 100 | DCHECK(_nums.empty()); | 105 | 100 | size_t rows = 0; | 106 | 273 | for (const auto& i : _sorted_nums_vec) { | 107 | 273 | rows += i.size(); | 108 | 273 | } | 109 | 100 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 100 | double u = (rows - 1) * quantile; | 111 | 100 | 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 | 100 | size_t target = reverse ? rows - index - 2 : index; | 120 | 100 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 100 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 100 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 100 | return first_number + | 128 | 100 | (u - static_cast<double>(index)) * | 129 | 100 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 100 | } | 131 | 444 | } |
_ZN5doris6CountsIlE9terminateEd Line | Count | Source | 78 | 128 | double terminate(double quantile) { | 79 | 128 | if (_sorted_nums_vec.size() <= 1) { | 80 | 107 | if (_sorted_nums_vec.size() == 1) { | 81 | 37 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 37 | } | 83 | | | 84 | 107 | 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 | 107 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 1 | pdqsort(_nums.begin(), _nums.end()); | 92 | 1 | } | 93 | | | 94 | 107 | if (quantile == 1 || _nums.size() == 1) { | 95 | 59 | return _nums.back(); | 96 | 59 | } | 97 | | | 98 | 48 | double u = (_nums.size() - 1) * quantile; | 99 | 48 | auto index = static_cast<uint32_t>(u); | 100 | 48 | return _nums[index] + | 101 | 48 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 48 | static_cast<double>(_nums[index])); | 103 | 107 | } else { | 104 | 21 | DCHECK(_nums.empty()); | 105 | 21 | size_t rows = 0; | 106 | 59 | for (const auto& i : _sorted_nums_vec) { | 107 | 59 | rows += i.size(); | 108 | 59 | } | 109 | 21 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 21 | double u = (rows - 1) * quantile; | 111 | 21 | 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 | 21 | size_t target = reverse ? rows - index - 2 : index; | 120 | 21 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 21 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 21 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 21 | return first_number + | 128 | 21 | (u - static_cast<double>(index)) * | 129 | 21 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 21 | } | 131 | 128 | } |
_ZN5doris6CountsInE9terminateEd Line | Count | Source | 78 | 33 | double terminate(double quantile) { | 79 | 33 | if (_sorted_nums_vec.size() <= 1) { | 80 | 30 | if (_sorted_nums_vec.size() == 1) { | 81 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 0 | } | 83 | | | 84 | 30 | 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 | 30 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 0 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | | | 94 | 30 | if (quantile == 1 || _nums.size() == 1) { | 95 | 24 | return _nums.back(); | 96 | 24 | } | 97 | | | 98 | 6 | double u = (_nums.size() - 1) * quantile; | 99 | 6 | auto index = static_cast<uint32_t>(u); | 100 | 6 | return _nums[index] + | 101 | 6 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 6 | static_cast<double>(_nums[index])); | 103 | 30 | } else { | 104 | 3 | DCHECK(_nums.empty()); | 105 | 3 | size_t rows = 0; | 106 | 6 | for (const auto& i : _sorted_nums_vec) { | 107 | 6 | rows += i.size(); | 108 | 6 | } | 109 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 3 | double u = (rows - 1) * quantile; | 111 | 3 | 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 | 3 | size_t target = reverse ? rows - index - 2 : index; | 120 | 3 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 3 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 3 | return first_number + | 128 | 3 | (u - static_cast<double>(index)) * | 129 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 3 | } | 131 | 33 | } |
_ZN5doris6CountsIfE9terminateEd Line | Count | Source | 78 | 3 | double terminate(double quantile) { | 79 | 3 | if (_sorted_nums_vec.size() <= 1) { | 80 | 0 | if (_sorted_nums_vec.size() == 1) { | 81 | 0 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 0 | } | 83 | |
| 84 | 0 | 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 | 0 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 0 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | |
| 94 | 0 | if (quantile == 1 || _nums.size() == 1) { | 95 | 0 | return _nums.back(); | 96 | 0 | } | 97 | | | 98 | 0 | double u = (_nums.size() - 1) * quantile; | 99 | 0 | auto index = static_cast<uint32_t>(u); | 100 | 0 | return _nums[index] + | 101 | 0 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 0 | static_cast<double>(_nums[index])); | 103 | 3 | } else { | 104 | 3 | DCHECK(_nums.empty()); | 105 | 3 | size_t rows = 0; | 106 | 6 | for (const auto& i : _sorted_nums_vec) { | 107 | 6 | rows += i.size(); | 108 | 6 | } | 109 | 3 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 3 | double u = (rows - 1) * quantile; | 111 | 3 | 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 | 3 | size_t target = reverse ? rows - index - 2 : index; | 120 | 3 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 3 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 3 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 3 | return first_number + | 128 | 3 | (u - static_cast<double>(index)) * | 129 | 3 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 3 | } | 131 | 3 | } |
_ZN5doris6CountsIdE9terminateEd Line | Count | Source | 78 | 136 | double terminate(double quantile) { | 79 | 136 | if (_sorted_nums_vec.size() <= 1) { | 80 | 109 | if (_sorted_nums_vec.size() == 1) { | 81 | 26 | _nums = std::move(_sorted_nums_vec[0]); | 82 | 26 | } | 83 | | | 84 | 109 | 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 | 109 | if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) { | 91 | 0 | pdqsort(_nums.begin(), _nums.end()); | 92 | 0 | } | 93 | | | 94 | 109 | if (quantile == 1 || _nums.size() == 1) { | 95 | 30 | return _nums.back(); | 96 | 30 | } | 97 | | | 98 | 79 | double u = (_nums.size() - 1) * quantile; | 99 | 79 | auto index = static_cast<uint32_t>(u); | 100 | 79 | return _nums[index] + | 101 | 79 | (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) - | 102 | 79 | static_cast<double>(_nums[index])); | 103 | 109 | } else { | 104 | 27 | DCHECK(_nums.empty()); | 105 | 27 | size_t rows = 0; | 106 | 66 | for (const auto& i : _sorted_nums_vec) { | 107 | 66 | rows += i.size(); | 108 | 66 | } | 109 | 27 | const bool reverse = quantile > 0.5 && rows > 2; | 110 | 27 | double u = (rows - 1) * quantile; | 111 | 27 | 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 | 27 | size_t target = reverse ? rows - index - 2 : index; | 120 | 27 | if (quantile == 1) { | 121 | 0 | target = 0; | 122 | 0 | } | 123 | 27 | auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse); | 124 | 27 | if (quantile == 1) { | 125 | 0 | return second_number; | 126 | 0 | } | 127 | 27 | return first_number + | 128 | 27 | (u - static_cast<double>(index)) * | 129 | 27 | (static_cast<double>(second_number) - static_cast<double>(first_number)); | 130 | 27 | } | 131 | 136 | } |
|
132 | | |
133 | | private: |
134 | | struct Node { |
135 | | Ty value; |
136 | | int array_index; |
137 | | int64_t element_index; |
138 | | |
139 | 1.42k | auto operator<=>(const Node& other) const { return value <=> other.value; }_ZNK5doris6CountsIaE4NodessERKS2_ Line | Count | Source | 139 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIsE4NodessERKS2_ Line | Count | Source | 139 | 25 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIiE4NodessERKS2_ Line | Count | Source | 139 | 942 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIlE4NodessERKS2_ Line | Count | Source | 139 | 376 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsInE4NodessERKS2_ Line | Count | Source | 139 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIfE4NodessERKS2_ Line | Count | Source | 139 | 6 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
_ZNK5doris6CountsIdE4NodessERKS2_ Line | Count | Source | 139 | 67 | auto operator<=>(const Node& other) const { return value <=> other.value; } |
|
140 | | }; |
141 | | |
142 | 299 | void _convert_sorted_num_vec_to_nums() { |
143 | 299 | size_t rows = 0; |
144 | 596 | for (const auto& i : _sorted_nums_vec) { |
145 | 596 | rows += i.size(); |
146 | 596 | } |
147 | 299 | _nums.resize(rows); |
148 | 299 | size_t count = 0; |
149 | | |
150 | 299 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
151 | 895 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
152 | 596 | if (!_sorted_nums_vec[i].empty()) { |
153 | 596 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
154 | 596 | } |
155 | 596 | } |
156 | | |
157 | 1.04k | while (!min_heap.empty()) { |
158 | 743 | Node node = min_heap.top(); |
159 | 743 | min_heap.pop(); |
160 | 743 | _nums[count++] = node.value; |
161 | 743 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
162 | 147 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
163 | 147 | min_heap.push(node); |
164 | 147 | } |
165 | 743 | } |
166 | 299 | _sorted_nums_vec.clear(); |
167 | 299 | } 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 | 143 | void _convert_sorted_num_vec_to_nums() { | 143 | 143 | size_t rows = 0; | 144 | 257 | for (const auto& i : _sorted_nums_vec) { | 145 | 257 | rows += i.size(); | 146 | 257 | } | 147 | 143 | _nums.resize(rows); | 148 | 143 | size_t count = 0; | 149 | | | 150 | 143 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 151 | 400 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 152 | 257 | if (!_sorted_nums_vec[i].empty()) { | 153 | 257 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 154 | 257 | } | 155 | 257 | } | 156 | | | 157 | 511 | while (!min_heap.empty()) { | 158 | 368 | Node node = min_heap.top(); | 159 | 368 | min_heap.pop(); | 160 | 368 | _nums[count++] = node.value; | 161 | 368 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 162 | 111 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 163 | 111 | min_heap.push(node); | 164 | 111 | } | 165 | 368 | } | 166 | 143 | _sorted_nums_vec.clear(); | 167 | 143 | } |
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 | 163 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { |
170 | 163 | Ty first_number = 0, second_number = 0; |
171 | 163 | size_t count = 0; |
172 | 163 | if (reverse) { |
173 | 31 | std::priority_queue<Node> max_heap; |
174 | 118 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
175 | 87 | if (!_sorted_nums_vec[i].empty()) { |
176 | 87 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, |
177 | 87 | _sorted_nums_vec[i].size() - 1); |
178 | 87 | } |
179 | 87 | } |
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 | 31 | second_number = node.value; |
186 | 82 | } else if (count == target + 1) { |
187 | 31 | first_number = node.value; |
188 | 31 | break; |
189 | 31 | } |
190 | 82 | ++count; |
191 | 82 | if (--node.element_index >= 0) { |
192 | 67 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
193 | 67 | max_heap.push(node); |
194 | 67 | } |
195 | 82 | } |
196 | | |
197 | 132 | } else { |
198 | 132 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; |
199 | 473 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { |
200 | 341 | if (!_sorted_nums_vec[i].empty()) { |
201 | 341 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); |
202 | 341 | } |
203 | 341 | } |
204 | | |
205 | 373 | while (!min_heap.empty()) { |
206 | 373 | Node node = min_heap.top(); |
207 | 373 | min_heap.pop(); |
208 | 373 | if (count == target) { |
209 | 132 | first_number = node.value; |
210 | 241 | } else if (count == target + 1) { |
211 | 132 | second_number = node.value; |
212 | 132 | break; |
213 | 132 | } |
214 | 241 | ++count; |
215 | 241 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { |
216 | 148 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; |
217 | 148 | min_heap.push(node); |
218 | 148 | } |
219 | 241 | } |
220 | 132 | } |
221 | | |
222 | 163 | return {first_number, second_number}; |
223 | 163 | } _ZN5doris6CountsIaE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 3 | Ty first_number = 0, second_number = 0; | 171 | 3 | size_t count = 0; | 172 | 3 | if (reverse) { | 173 | 1 | std::priority_queue<Node> max_heap; | 174 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 2 | if (!_sorted_nums_vec[i].empty()) { | 176 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 2 | _sorted_nums_vec[i].size() - 1); | 178 | 2 | } | 179 | 2 | } | 180 | | | 181 | 2 | while (!max_heap.empty()) { | 182 | 2 | Node node = max_heap.top(); | 183 | 2 | max_heap.pop(); | 184 | 2 | if (count == target) { | 185 | 1 | second_number = node.value; | 186 | 1 | } else if (count == target + 1) { | 187 | 1 | first_number = node.value; | 188 | 1 | break; | 189 | 1 | } | 190 | 1 | ++count; | 191 | 1 | if (--node.element_index >= 0) { | 192 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 1 | } | 196 | | | 197 | 2 | } else { | 198 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 4 | if (!_sorted_nums_vec[i].empty()) { | 201 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 4 | } | 203 | 4 | } | 204 | | | 205 | 6 | while (!min_heap.empty()) { | 206 | 6 | Node node = min_heap.top(); | 207 | 6 | min_heap.pop(); | 208 | 6 | if (count == target) { | 209 | 2 | first_number = node.value; | 210 | 4 | } else if (count == target + 1) { | 211 | 2 | second_number = node.value; | 212 | 2 | break; | 213 | 2 | } | 214 | 4 | ++count; | 215 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 2 | min_heap.push(node); | 218 | 2 | } | 219 | 4 | } | 220 | 2 | } | 221 | | | 222 | 3 | return {first_number, second_number}; | 223 | 3 | } |
_ZN5doris6CountsIsE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 6 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 6 | Ty first_number = 0, second_number = 0; | 171 | 6 | size_t count = 0; | 172 | 6 | if (reverse) { | 173 | 2 | std::priority_queue<Node> max_heap; | 174 | 6 | 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 | 8 | while (!max_heap.empty()) { | 182 | 8 | Node node = max_heap.top(); | 183 | 8 | max_heap.pop(); | 184 | 8 | if (count == target) { | 185 | 2 | second_number = node.value; | 186 | 6 | } else if (count == target + 1) { | 187 | 2 | first_number = node.value; | 188 | 2 | break; | 189 | 2 | } | 190 | 6 | ++count; | 191 | 6 | if (--node.element_index >= 0) { | 192 | 6 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 6 | max_heap.push(node); | 194 | 6 | } | 195 | 6 | } | 196 | | | 197 | 4 | } else { | 198 | 4 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 12 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 8 | if (!_sorted_nums_vec[i].empty()) { | 201 | 8 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 8 | } | 203 | 8 | } | 204 | | | 205 | 19 | while (!min_heap.empty()) { | 206 | 19 | Node node = min_heap.top(); | 207 | 19 | min_heap.pop(); | 208 | 19 | if (count == target) { | 209 | 4 | first_number = node.value; | 210 | 15 | } else if (count == target + 1) { | 211 | 4 | second_number = node.value; | 212 | 4 | break; | 213 | 4 | } | 214 | 15 | ++count; | 215 | 15 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 13 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 13 | min_heap.push(node); | 218 | 13 | } | 219 | 15 | } | 220 | 4 | } | 221 | | | 222 | 6 | return {first_number, second_number}; | 223 | 6 | } |
_ZN5doris6CountsIiE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 100 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 100 | Ty first_number = 0, second_number = 0; | 171 | 100 | size_t count = 0; | 172 | 100 | if (reverse) { | 173 | 11 | std::priority_queue<Node> max_heap; | 174 | 41 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 30 | if (!_sorted_nums_vec[i].empty()) { | 176 | 30 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 30 | _sorted_nums_vec[i].size() - 1); | 178 | 30 | } | 179 | 30 | } | 180 | | | 181 | 41 | while (!max_heap.empty()) { | 182 | 41 | Node node = max_heap.top(); | 183 | 41 | max_heap.pop(); | 184 | 41 | if (count == target) { | 185 | 11 | second_number = node.value; | 186 | 30 | } else if (count == target + 1) { | 187 | 11 | first_number = node.value; | 188 | 11 | break; | 189 | 11 | } | 190 | 30 | ++count; | 191 | 30 | if (--node.element_index >= 0) { | 192 | 23 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 23 | max_heap.push(node); | 194 | 23 | } | 195 | 30 | } | 196 | | | 197 | 89 | } else { | 198 | 89 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 332 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 243 | if (!_sorted_nums_vec[i].empty()) { | 201 | 243 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 243 | } | 203 | 243 | } | 204 | | | 205 | 250 | while (!min_heap.empty()) { | 206 | 250 | Node node = min_heap.top(); | 207 | 250 | min_heap.pop(); | 208 | 250 | if (count == target) { | 209 | 89 | first_number = node.value; | 210 | 161 | } else if (count == target + 1) { | 211 | 89 | second_number = node.value; | 212 | 89 | break; | 213 | 89 | } | 214 | 161 | ++count; | 215 | 161 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 102 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 102 | min_heap.push(node); | 218 | 102 | } | 219 | 161 | } | 220 | 89 | } | 221 | | | 222 | 100 | return {first_number, second_number}; | 223 | 100 | } |
_ZN5doris6CountsIlE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 21 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 21 | Ty first_number = 0, second_number = 0; | 171 | 21 | size_t count = 0; | 172 | 21 | if (reverse) { | 173 | 12 | std::priority_queue<Node> max_heap; | 174 | 51 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 39 | if (!_sorted_nums_vec[i].empty()) { | 176 | 39 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 39 | _sorted_nums_vec[i].size() - 1); | 178 | 39 | } | 179 | 39 | } | 180 | | | 181 | 51 | while (!max_heap.empty()) { | 182 | 51 | Node node = max_heap.top(); | 183 | 51 | max_heap.pop(); | 184 | 51 | if (count == target) { | 185 | 12 | second_number = node.value; | 186 | 39 | } else if (count == target + 1) { | 187 | 12 | first_number = node.value; | 188 | 12 | break; | 189 | 12 | } | 190 | 39 | ++count; | 191 | 39 | if (--node.element_index >= 0) { | 192 | 34 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 34 | max_heap.push(node); | 194 | 34 | } | 195 | 39 | } | 196 | | | 197 | 12 | } else { | 198 | 9 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 29 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 20 | if (!_sorted_nums_vec[i].empty()) { | 201 | 20 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 20 | } | 203 | 20 | } | 204 | | | 205 | 28 | while (!min_heap.empty()) { | 206 | 28 | Node node = min_heap.top(); | 207 | 28 | min_heap.pop(); | 208 | 28 | if (count == target) { | 209 | 9 | first_number = node.value; | 210 | 19 | } else if (count == target + 1) { | 211 | 9 | second_number = node.value; | 212 | 9 | break; | 213 | 9 | } | 214 | 19 | ++count; | 215 | 19 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 16 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 16 | min_heap.push(node); | 218 | 16 | } | 219 | 19 | } | 220 | 9 | } | 221 | | | 222 | 21 | return {first_number, second_number}; | 223 | 21 | } |
_ZN5doris6CountsInE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 3 | Ty first_number = 0, second_number = 0; | 171 | 3 | size_t count = 0; | 172 | 3 | if (reverse) { | 173 | 1 | std::priority_queue<Node> max_heap; | 174 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 2 | if (!_sorted_nums_vec[i].empty()) { | 176 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 2 | _sorted_nums_vec[i].size() - 1); | 178 | 2 | } | 179 | 2 | } | 180 | | | 181 | 2 | while (!max_heap.empty()) { | 182 | 2 | Node node = max_heap.top(); | 183 | 2 | max_heap.pop(); | 184 | 2 | if (count == target) { | 185 | 1 | second_number = node.value; | 186 | 1 | } else if (count == target + 1) { | 187 | 1 | first_number = node.value; | 188 | 1 | break; | 189 | 1 | } | 190 | 1 | ++count; | 191 | 1 | if (--node.element_index >= 0) { | 192 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 1 | } | 196 | | | 197 | 2 | } else { | 198 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 4 | if (!_sorted_nums_vec[i].empty()) { | 201 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 4 | } | 203 | 4 | } | 204 | | | 205 | 6 | while (!min_heap.empty()) { | 206 | 6 | Node node = min_heap.top(); | 207 | 6 | min_heap.pop(); | 208 | 6 | if (count == target) { | 209 | 2 | first_number = node.value; | 210 | 4 | } else if (count == target + 1) { | 211 | 2 | second_number = node.value; | 212 | 2 | break; | 213 | 2 | } | 214 | 4 | ++count; | 215 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 2 | min_heap.push(node); | 218 | 2 | } | 219 | 4 | } | 220 | 2 | } | 221 | | | 222 | 3 | return {first_number, second_number}; | 223 | 3 | } |
_ZN5doris6CountsIfE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 3 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 3 | Ty first_number = 0, second_number = 0; | 171 | 3 | size_t count = 0; | 172 | 3 | if (reverse) { | 173 | 1 | std::priority_queue<Node> max_heap; | 174 | 3 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 2 | if (!_sorted_nums_vec[i].empty()) { | 176 | 2 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 2 | _sorted_nums_vec[i].size() - 1); | 178 | 2 | } | 179 | 2 | } | 180 | | | 181 | 2 | while (!max_heap.empty()) { | 182 | 2 | Node node = max_heap.top(); | 183 | 2 | max_heap.pop(); | 184 | 2 | if (count == target) { | 185 | 1 | second_number = node.value; | 186 | 1 | } else if (count == target + 1) { | 187 | 1 | first_number = node.value; | 188 | 1 | break; | 189 | 1 | } | 190 | 1 | ++count; | 191 | 1 | if (--node.element_index >= 0) { | 192 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 1 | } | 196 | | | 197 | 2 | } else { | 198 | 2 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 6 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 4 | if (!_sorted_nums_vec[i].empty()) { | 201 | 4 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 4 | } | 203 | 4 | } | 204 | | | 205 | 6 | while (!min_heap.empty()) { | 206 | 6 | Node node = min_heap.top(); | 207 | 6 | min_heap.pop(); | 208 | 6 | if (count == target) { | 209 | 2 | first_number = node.value; | 210 | 4 | } else if (count == target + 1) { | 211 | 2 | second_number = node.value; | 212 | 2 | break; | 213 | 2 | } | 214 | 4 | ++count; | 215 | 4 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 2 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 2 | min_heap.push(node); | 218 | 2 | } | 219 | 4 | } | 220 | 2 | } | 221 | | | 222 | 3 | return {first_number, second_number}; | 223 | 3 | } |
_ZN5doris6CountsIdE27_merge_sort_and_get_numbersElb Line | Count | Source | 169 | 27 | std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) { | 170 | 27 | Ty first_number = 0, second_number = 0; | 171 | 27 | size_t count = 0; | 172 | 27 | if (reverse) { | 173 | 3 | std::priority_queue<Node> max_heap; | 174 | 11 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 175 | 8 | if (!_sorted_nums_vec[i].empty()) { | 176 | 8 | max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i, | 177 | 8 | _sorted_nums_vec[i].size() - 1); | 178 | 8 | } | 179 | 8 | } | 180 | | | 181 | 7 | while (!max_heap.empty()) { | 182 | 7 | Node node = max_heap.top(); | 183 | 7 | max_heap.pop(); | 184 | 7 | if (count == target) { | 185 | 3 | second_number = node.value; | 186 | 4 | } else if (count == target + 1) { | 187 | 3 | first_number = node.value; | 188 | 3 | break; | 189 | 3 | } | 190 | 4 | ++count; | 191 | 4 | if (--node.element_index >= 0) { | 192 | 1 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 193 | 1 | max_heap.push(node); | 194 | 1 | } | 195 | 4 | } | 196 | | | 197 | 24 | } else { | 198 | 24 | std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap; | 199 | 82 | for (int i = 0; i < _sorted_nums_vec.size(); ++i) { | 200 | 58 | if (!_sorted_nums_vec[i].empty()) { | 201 | 58 | min_heap.emplace(_sorted_nums_vec[i][0], i, 0); | 202 | 58 | } | 203 | 58 | } | 204 | | | 205 | 58 | while (!min_heap.empty()) { | 206 | 58 | Node node = min_heap.top(); | 207 | 58 | min_heap.pop(); | 208 | 58 | if (count == target) { | 209 | 24 | first_number = node.value; | 210 | 34 | } else if (count == target + 1) { | 211 | 24 | second_number = node.value; | 212 | 24 | break; | 213 | 24 | } | 214 | 34 | ++count; | 215 | 34 | if (++node.element_index < _sorted_nums_vec[node.array_index].size()) { | 216 | 11 | node.value = _sorted_nums_vec[node.array_index][node.element_index]; | 217 | 11 | min_heap.push(node); | 218 | 11 | } | 219 | 34 | } | 220 | 24 | } | 221 | | | 222 | 27 | return {first_number, second_number}; | 223 | 27 | } |
|
224 | | |
225 | | vectorized::PODArray<Ty> _nums; |
226 | | std::vector<vectorized::PODArray<Ty>> _sorted_nums_vec; |
227 | | }; |
228 | | |
229 | | } // namespace doris |