Coverage Report

Created: 2026-02-13 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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.15k
    Counts() = default;
_ZN5doris6CountsIaEC2Ev
Line
Count
Source
35
47
    Counts() = default;
_ZN5doris6CountsIsEC2Ev
Line
Count
Source
35
199
    Counts() = default;
_ZN5doris6CountsIiEC2Ev
Line
Count
Source
35
1.89k
    Counts() = default;
_ZN5doris6CountsIlEC2Ev
Line
Count
Source
35
765
    Counts() = default;
_ZN5doris6CountsInEC2Ev
Line
Count
Source
35
43
    Counts() = default;
_ZN5doris6CountsIfEC2Ev
Line
Count
Source
35
13
    Counts() = default;
_ZN5doris6CountsIdEC2Ev
Line
Count
Source
35
194
    Counts() = default;
36
37
1.06k
    void merge(Counts* other) {
38
1.06k
        if (other != nullptr && !other->_nums.empty()) {
39
1.06k
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
1.06k
        }
41
1.06k
    }
_ZN5doris6CountsIaE5mergeEPS1_
Line
Count
Source
37
5
    void merge(Counts* other) {
38
5
        if (other != nullptr && !other->_nums.empty()) {
39
5
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
5
        }
41
5
    }
_ZN5doris6CountsIsE5mergeEPS1_
Line
Count
Source
37
8
    void merge(Counts* other) {
38
8
        if (other != nullptr && !other->_nums.empty()) {
39
8
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
8
        }
41
8
    }
_ZN5doris6CountsIiE5mergeEPS1_
Line
Count
Source
37
667
    void merge(Counts* other) {
38
667
        if (other != nullptr && !other->_nums.empty()) {
39
667
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
667
        }
41
667
    }
_ZN5doris6CountsIlE5mergeEPS1_
Line
Count
Source
37
315
    void merge(Counts* other) {
38
315
        if (other != nullptr && !other->_nums.empty()) {
39
315
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
315
        }
41
315
    }
_ZN5doris6CountsInE5mergeEPS1_
Line
Count
Source
37
5
    void merge(Counts* other) {
38
5
        if (other != nullptr && !other->_nums.empty()) {
39
5
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
5
        }
41
5
    }
_ZN5doris6CountsIfE5mergeEPS1_
Line
Count
Source
37
5
    void merge(Counts* other) {
38
5
        if (other != nullptr && !other->_nums.empty()) {
39
5
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
5
        }
41
5
    }
_ZN5doris6CountsIdE5mergeEPS1_
Line
Count
Source
37
55
    void merge(Counts* other) {
38
55
        if (other != nullptr && !other->_nums.empty()) {
39
55
            _sorted_nums_vec.emplace_back(std::move(other->_nums));
40
55
        }
41
55
    }
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.45k
    void serialize(vectorized::BufferWritable& buf) {
58
1.45k
        if (!_nums.empty()) {
59
1.17k
            pdqsort(_nums.begin(), _nums.end());
60
1.17k
            size_t size = _nums.size();
61
1.17k
            buf.write_binary(size);
62
1.17k
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
1.17k
        } else {
64
            // convert _sorted_nums_vec to _nums and do seiralize again
65
274
            _convert_sorted_num_vec_to_nums();
66
274
            serialize(buf);
67
274
        }
68
1.45k
    }
_ZN5doris6CountsIaE9serializeERNS_10vectorized14BufferWritableE
Line
Count
Source
57
5
    void serialize(vectorized::BufferWritable& buf) {
58
5
        if (!_nums.empty()) {
59
5
            pdqsort(_nums.begin(), _nums.end());
60
5
            size_t size = _nums.size();
61
5
            buf.write_binary(size);
62
5
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
5
        } else {
64
            // 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
5
    }
_ZN5doris6CountsIsE9serializeERNS_10vectorized14BufferWritableE
Line
Count
Source
57
8
    void serialize(vectorized::BufferWritable& buf) {
58
8
        if (!_nums.empty()) {
59
8
            pdqsort(_nums.begin(), _nums.end());
60
8
            size_t size = _nums.size();
61
8
            buf.write_binary(size);
62
8
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
8
        } 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
8
    }
_ZN5doris6CountsIiE9serializeERNS_10vectorized14BufferWritableE
Line
Count
Source
57
940
    void serialize(vectorized::BufferWritable& buf) {
58
940
        if (!_nums.empty()) {
59
784
            pdqsort(_nums.begin(), _nums.end());
60
784
            size_t size = _nums.size();
61
784
            buf.write_binary(size);
62
784
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
784
        } 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
940
    }
_ZN5doris6CountsIlE9serializeERNS_10vectorized14BufferWritableE
Line
Count
Source
57
433
    void serialize(vectorized::BufferWritable& buf) {
58
433
        if (!_nums.empty()) {
59
315
            pdqsort(_nums.begin(), _nums.end());
60
315
            size_t size = _nums.size();
61
315
            buf.write_binary(size);
62
315
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
315
        } else {
64
            // convert _sorted_nums_vec to _nums and do seiralize again
65
118
            _convert_sorted_num_vec_to_nums();
66
118
            serialize(buf);
67
118
        }
68
433
    }
_ZN5doris6CountsInE9serializeERNS_10vectorized14BufferWritableE
Line
Count
Source
57
5
    void serialize(vectorized::BufferWritable& buf) {
58
5
        if (!_nums.empty()) {
59
5
            pdqsort(_nums.begin(), _nums.end());
60
5
            size_t size = _nums.size();
61
5
            buf.write_binary(size);
62
5
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
5
        } else {
64
            // 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
5
    }
_ZN5doris6CountsIfE9serializeERNS_10vectorized14BufferWritableE
Line
Count
Source
57
5
    void serialize(vectorized::BufferWritable& buf) {
58
5
        if (!_nums.empty()) {
59
5
            pdqsort(_nums.begin(), _nums.end());
60
5
            size_t size = _nums.size();
61
5
            buf.write_binary(size);
62
5
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
5
        } else {
64
            // 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
5
    }
_ZN5doris6CountsIdE9serializeERNS_10vectorized14BufferWritableE
Line
Count
Source
57
55
    void serialize(vectorized::BufferWritable& buf) {
58
55
        if (!_nums.empty()) {
59
55
            pdqsort(_nums.begin(), _nums.end());
60
55
            size_t size = _nums.size();
61
55
            buf.write_binary(size);
62
55
            buf.write(reinterpret_cast<const char*>(_nums.data()), sizeof(Ty) * size);
63
55
        } 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
55
    }
69
70
1.06k
    void unserialize(vectorized::BufferReadable& buf) {
71
1.06k
        size_t size;
72
1.06k
        buf.read_binary(size);
73
1.06k
        _nums.resize(size);
74
1.06k
        auto buff = buf.read(sizeof(Ty) * size);
75
1.06k
        memcpy(_nums.data(), buff.data, buff.size);
76
1.06k
    }
_ZN5doris6CountsIaE11unserializeERNS_10vectorized14BufferReadableE
Line
Count
Source
70
5
    void unserialize(vectorized::BufferReadable& buf) {
71
5
        size_t size;
72
5
        buf.read_binary(size);
73
5
        _nums.resize(size);
74
5
        auto buff = buf.read(sizeof(Ty) * size);
75
5
        memcpy(_nums.data(), buff.data, buff.size);
76
5
    }
_ZN5doris6CountsIsE11unserializeERNS_10vectorized14BufferReadableE
Line
Count
Source
70
8
    void unserialize(vectorized::BufferReadable& buf) {
71
8
        size_t size;
72
8
        buf.read_binary(size);
73
8
        _nums.resize(size);
74
8
        auto buff = buf.read(sizeof(Ty) * size);
75
8
        memcpy(_nums.data(), buff.data, buff.size);
76
8
    }
_ZN5doris6CountsIiE11unserializeERNS_10vectorized14BufferReadableE
Line
Count
Source
70
667
    void unserialize(vectorized::BufferReadable& buf) {
71
667
        size_t size;
72
667
        buf.read_binary(size);
73
667
        _nums.resize(size);
74
667
        auto buff = buf.read(sizeof(Ty) * size);
75
667
        memcpy(_nums.data(), buff.data, buff.size);
76
667
    }
_ZN5doris6CountsIlE11unserializeERNS_10vectorized14BufferReadableE
Line
Count
Source
70
315
    void unserialize(vectorized::BufferReadable& buf) {
71
315
        size_t size;
72
315
        buf.read_binary(size);
73
315
        _nums.resize(size);
74
315
        auto buff = buf.read(sizeof(Ty) * size);
75
315
        memcpy(_nums.data(), buff.data, buff.size);
76
315
    }
_ZN5doris6CountsInE11unserializeERNS_10vectorized14BufferReadableE
Line
Count
Source
70
5
    void unserialize(vectorized::BufferReadable& buf) {
71
5
        size_t size;
72
5
        buf.read_binary(size);
73
5
        _nums.resize(size);
74
5
        auto buff = buf.read(sizeof(Ty) * size);
75
5
        memcpy(_nums.data(), buff.data, buff.size);
76
5
    }
_ZN5doris6CountsIfE11unserializeERNS_10vectorized14BufferReadableE
Line
Count
Source
70
5
    void unserialize(vectorized::BufferReadable& buf) {
71
5
        size_t size;
72
5
        buf.read_binary(size);
73
5
        _nums.resize(size);
74
5
        auto buff = buf.read(sizeof(Ty) * size);
75
5
        memcpy(_nums.data(), buff.data, buff.size);
76
5
    }
_ZN5doris6CountsIdE11unserializeERNS_10vectorized14BufferReadableE
Line
Count
Source
70
55
    void unserialize(vectorized::BufferReadable& buf) {
71
55
        size_t size;
72
55
        buf.read_binary(size);
73
55
        _nums.resize(size);
74
55
        auto buff = buf.read(sizeof(Ty) * size);
75
55
        memcpy(_nums.data(), buff.data, buff.size);
76
55
    }
77
78
1.10k
    double terminate(double quantile) {
79
1.10k
        if (_sorted_nums_vec.size() <= 1) {
80
1.08k
            if (_sorted_nums_vec.size() == 1) {
81
431
                _nums = std::move(_sorted_nums_vec[0]);
82
431
            }
83
84
1.08k
            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
1.08k
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
180
                pdqsort(_nums.begin(), _nums.end());
92
180
            }
93
94
1.08k
            if (quantile == 1 || _nums.size() == 1) {
95
473
                return _nums.back();
96
473
            }
97
98
611
            double u = (_nums.size() - 1) * quantile;
99
611
            auto index = static_cast<uint32_t>(u);
100
611
            return _nums[index] +
101
611
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
611
                                                       static_cast<double>(_nums[index]));
103
1.08k
        } else {
104
21
            DCHECK(_nums.empty());
105
21
            size_t rows = 0;
106
57
            for (const auto& i : _sorted_nums_vec) {
107
57
                rows += i.size();
108
57
            }
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
1.10k
    }
_ZN5doris6CountsIaE9terminateEd
Line
Count
Source
78
61
    double terminate(double quantile) {
79
61
        if (_sorted_nums_vec.size() <= 1) {
80
59
            if (_sorted_nums_vec.size() == 1) {
81
1
                _nums = std::move(_sorted_nums_vec[0]);
82
1
            }
83
84
59
            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
59
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
24
                pdqsort(_nums.begin(), _nums.end());
92
24
            }
93
94
59
            if (quantile == 1 || _nums.size() == 1) {
95
34
                return _nums.back();
96
34
            }
97
98
25
            double u = (_nums.size() - 1) * quantile;
99
25
            auto index = static_cast<uint32_t>(u);
100
25
            return _nums[index] +
101
25
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
25
                                                       static_cast<double>(_nums[index]));
103
59
        } else {
104
2
            DCHECK(_nums.empty());
105
2
            size_t rows = 0;
106
4
            for (const auto& i : _sorted_nums_vec) {
107
4
                rows += i.size();
108
4
            }
109
2
            const bool reverse = quantile > 0.5 && rows > 2;
110
2
            double u = (rows - 1) * quantile;
111
2
            auto index = static_cast<uint32_t>(u);
112
            // 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
2
            size_t target = reverse ? rows - index - 2 : index;
120
2
            if (quantile == 1) {
121
0
                target = 0;
122
0
            }
123
2
            auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse);
124
2
            if (quantile == 1) {
125
0
                return second_number;
126
0
            }
127
2
            return first_number +
128
2
                   (u - static_cast<double>(index)) *
129
2
                           (static_cast<double>(second_number) - static_cast<double>(first_number));
130
2
        }
131
61
    }
_ZN5doris6CountsIsE9terminateEd
Line
Count
Source
78
300
    double terminate(double quantile) {
79
300
        if (_sorted_nums_vec.size() <= 1) {
80
298
            if (_sorted_nums_vec.size() == 1) {
81
4
                _nums = std::move(_sorted_nums_vec[0]);
82
4
            }
83
84
298
            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
298
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
144
                pdqsort(_nums.begin(), _nums.end());
92
144
            }
93
94
298
            if (quantile == 1 || _nums.size() == 1) {
95
87
                return _nums.back();
96
87
            }
97
98
211
            double u = (_nums.size() - 1) * quantile;
99
211
            auto index = static_cast<uint32_t>(u);
100
211
            return _nums[index] +
101
211
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
211
                                                       static_cast<double>(_nums[index]));
103
298
        } else {
104
2
            DCHECK(_nums.empty());
105
2
            size_t rows = 0;
106
4
            for (const auto& i : _sorted_nums_vec) {
107
4
                rows += i.size();
108
4
            }
109
2
            const bool reverse = quantile > 0.5 && rows > 2;
110
2
            double u = (rows - 1) * quantile;
111
2
            auto index = static_cast<uint32_t>(u);
112
            // 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
2
            size_t target = reverse ? rows - index - 2 : index;
120
2
            if (quantile == 1) {
121
0
                target = 0;
122
0
            }
123
2
            auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse);
124
2
            if (quantile == 1) {
125
0
                return second_number;
126
0
            }
127
2
            return first_number +
128
2
                   (u - static_cast<double>(index)) *
129
2
                           (static_cast<double>(second_number) - static_cast<double>(first_number));
130
2
        }
131
300
    }
_ZN5doris6CountsIiE9terminateEd
Line
Count
Source
78
444
    double terminate(double quantile) {
79
444
        if (_sorted_nums_vec.size() <= 1) {
80
442
            if (_sorted_nums_vec.size() == 1) {
81
324
                _nums = std::move(_sorted_nums_vec[0]);
82
324
            }
83
84
442
            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
442
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
11
                pdqsort(_nums.begin(), _nums.end());
92
11
            }
93
94
442
            if (quantile == 1 || _nums.size() == 1) {
95
239
                return _nums.back();
96
239
            }
97
98
203
            double u = (_nums.size() - 1) * quantile;
99
203
            auto index = static_cast<uint32_t>(u);
100
203
            return _nums[index] +
101
203
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
203
                                                       static_cast<double>(_nums[index]));
103
442
        } else {
104
2
            DCHECK(_nums.empty());
105
2
            size_t rows = 0;
106
4
            for (const auto& i : _sorted_nums_vec) {
107
4
                rows += i.size();
108
4
            }
109
2
            const bool reverse = quantile > 0.5 && rows > 2;
110
2
            double u = (rows - 1) * quantile;
111
2
            auto index = static_cast<uint32_t>(u);
112
            // 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
2
            size_t target = reverse ? rows - index - 2 : index;
120
2
            if (quantile == 1) {
121
0
                target = 0;
122
0
            }
123
2
            auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse);
124
2
            if (quantile == 1) {
125
0
                return second_number;
126
0
            }
127
2
            return first_number +
128
2
                   (u - static_cast<double>(index)) *
129
2
                           (static_cast<double>(second_number) - static_cast<double>(first_number));
130
2
        }
131
444
    }
_ZN5doris6CountsIlE9terminateEd
Line
Count
Source
78
128
    double terminate(double quantile) {
79
128
        if (_sorted_nums_vec.size() <= 1) {
80
119
            if (_sorted_nums_vec.size() == 1) {
81
49
                _nums = std::move(_sorted_nums_vec[0]);
82
49
            }
83
84
119
            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
119
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
1
                pdqsort(_nums.begin(), _nums.end());
92
1
            }
93
94
119
            if (quantile == 1 || _nums.size() == 1) {
95
59
                return _nums.back();
96
59
            }
97
98
60
            double u = (_nums.size() - 1) * quantile;
99
60
            auto index = static_cast<uint32_t>(u);
100
60
            return _nums[index] +
101
60
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
60
                                                       static_cast<double>(_nums[index]));
103
119
        } else {
104
9
            DCHECK(_nums.empty());
105
9
            size_t rows = 0;
106
33
            for (const auto& i : _sorted_nums_vec) {
107
33
                rows += i.size();
108
33
            }
109
9
            const bool reverse = quantile > 0.5 && rows > 2;
110
9
            double u = (rows - 1) * quantile;
111
9
            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
9
            size_t target = reverse ? rows - index - 2 : index;
120
9
            if (quantile == 1) {
121
0
                target = 0;
122
0
            }
123
9
            auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse);
124
9
            if (quantile == 1) {
125
0
                return second_number;
126
0
            }
127
9
            return first_number +
128
9
                   (u - static_cast<double>(index)) *
129
9
                           (static_cast<double>(second_number) - static_cast<double>(first_number));
130
9
        }
131
128
    }
_ZN5doris6CountsInE9terminateEd
Line
Count
Source
78
33
    double terminate(double quantile) {
79
33
        if (_sorted_nums_vec.size() <= 1) {
80
31
            if (_sorted_nums_vec.size() == 1) {
81
1
                _nums = std::move(_sorted_nums_vec[0]);
82
1
            }
83
84
31
            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
31
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
0
                pdqsort(_nums.begin(), _nums.end());
92
0
            }
93
94
31
            if (quantile == 1 || _nums.size() == 1) {
95
24
                return _nums.back();
96
24
            }
97
98
7
            double u = (_nums.size() - 1) * quantile;
99
7
            auto index = static_cast<uint32_t>(u);
100
7
            return _nums[index] +
101
7
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
7
                                                       static_cast<double>(_nums[index]));
103
31
        } else {
104
2
            DCHECK(_nums.empty());
105
2
            size_t rows = 0;
106
4
            for (const auto& i : _sorted_nums_vec) {
107
4
                rows += i.size();
108
4
            }
109
2
            const bool reverse = quantile > 0.5 && rows > 2;
110
2
            double u = (rows - 1) * quantile;
111
2
            auto index = static_cast<uint32_t>(u);
112
            // 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
2
            size_t target = reverse ? rows - index - 2 : index;
120
2
            if (quantile == 1) {
121
0
                target = 0;
122
0
            }
123
2
            auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse);
124
2
            if (quantile == 1) {
125
0
                return second_number;
126
0
            }
127
2
            return first_number +
128
2
                   (u - static_cast<double>(index)) *
129
2
                           (static_cast<double>(second_number) - static_cast<double>(first_number));
130
2
        }
131
33
    }
_ZN5doris6CountsIfE9terminateEd
Line
Count
Source
78
3
    double terminate(double quantile) {
79
3
        if (_sorted_nums_vec.size() <= 1) {
80
1
            if (_sorted_nums_vec.size() == 1) {
81
1
                _nums = std::move(_sorted_nums_vec[0]);
82
1
            }
83
84
1
            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
1
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
0
                pdqsort(_nums.begin(), _nums.end());
92
0
            }
93
94
1
            if (quantile == 1 || _nums.size() == 1) {
95
0
                return _nums.back();
96
0
            }
97
98
1
            double u = (_nums.size() - 1) * quantile;
99
1
            auto index = static_cast<uint32_t>(u);
100
1
            return _nums[index] +
101
1
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
1
                                                       static_cast<double>(_nums[index]));
103
2
        } else {
104
2
            DCHECK(_nums.empty());
105
2
            size_t rows = 0;
106
4
            for (const auto& i : _sorted_nums_vec) {
107
4
                rows += i.size();
108
4
            }
109
2
            const bool reverse = quantile > 0.5 && rows > 2;
110
2
            double u = (rows - 1) * quantile;
111
2
            auto index = static_cast<uint32_t>(u);
112
            // 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
2
            size_t target = reverse ? rows - index - 2 : index;
120
2
            if (quantile == 1) {
121
0
                target = 0;
122
0
            }
123
2
            auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse);
124
2
            if (quantile == 1) {
125
0
                return second_number;
126
0
            }
127
2
            return first_number +
128
2
                   (u - static_cast<double>(index)) *
129
2
                           (static_cast<double>(second_number) - static_cast<double>(first_number));
130
2
        }
131
3
    }
_ZN5doris6CountsIdE9terminateEd
Line
Count
Source
78
136
    double terminate(double quantile) {
79
136
        if (_sorted_nums_vec.size() <= 1) {
80
134
            if (_sorted_nums_vec.size() == 1) {
81
51
                _nums = std::move(_sorted_nums_vec[0]);
82
51
            }
83
84
134
            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
134
            if (UNLIKELY(!std::is_sorted(_nums.begin(), _nums.end()))) {
91
0
                pdqsort(_nums.begin(), _nums.end());
92
0
            }
93
94
134
            if (quantile == 1 || _nums.size() == 1) {
95
30
                return _nums.back();
96
30
            }
97
98
104
            double u = (_nums.size() - 1) * quantile;
99
104
            auto index = static_cast<uint32_t>(u);
100
104
            return _nums[index] +
101
104
                   (u - static_cast<double>(index)) * (static_cast<double>(_nums[index + 1]) -
102
104
                                                       static_cast<double>(_nums[index]));
103
134
        } else {
104
2
            DCHECK(_nums.empty());
105
2
            size_t rows = 0;
106
4
            for (const auto& i : _sorted_nums_vec) {
107
4
                rows += i.size();
108
4
            }
109
2
            const bool reverse = quantile > 0.5 && rows > 2;
110
2
            double u = (rows - 1) * quantile;
111
2
            auto index = static_cast<uint32_t>(u);
112
            // 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
2
            size_t target = reverse ? rows - index - 2 : index;
120
2
            if (quantile == 1) {
121
0
                target = 0;
122
0
            }
123
2
            auto [first_number, second_number] = _merge_sort_and_get_numbers(target, reverse);
124
2
            if (quantile == 1) {
125
0
                return second_number;
126
0
            }
127
2
            return first_number +
128
2
                   (u - static_cast<double>(index)) *
129
2
                           (static_cast<double>(second_number) - static_cast<double>(first_number));
130
2
        }
131
136
    }
132
133
private:
134
    struct Node {
135
        Ty value;
136
        int array_index;
137
        int64_t element_index;
138
139
656
        auto operator<=>(const Node& other) const { return value <=> other.value; }
_ZNK5doris6CountsIaE4NodessERKS2_
Line
Count
Source
139
4
        auto operator<=>(const Node& other) const { return value <=> other.value; }
_ZNK5doris6CountsIsE4NodessERKS2_
Line
Count
Source
139
4
        auto operator<=>(const Node& other) const { return value <=> other.value; }
_ZNK5doris6CountsIiE4NodessERKS2_
Line
Count
Source
139
295
        auto operator<=>(const Node& other) const { return value <=> other.value; }
_ZNK5doris6CountsIlE4NodessERKS2_
Line
Count
Source
139
342
        auto operator<=>(const Node& other) const { return value <=> other.value; }
_ZNK5doris6CountsInE4NodessERKS2_
Line
Count
Source
139
4
        auto operator<=>(const Node& other) const { return value <=> other.value; }
_ZNK5doris6CountsIfE4NodessERKS2_
Line
Count
Source
139
4
        auto operator<=>(const Node& other) const { return value <=> other.value; }
_ZNK5doris6CountsIdE4NodessERKS2_
Line
Count
Source
139
3
        auto operator<=>(const Node& other) const { return value <=> other.value; }
140
    };
141
142
274
    void _convert_sorted_num_vec_to_nums() {
143
274
        size_t rows = 0;
144
572
        for (const auto& i : _sorted_nums_vec) {
145
572
            rows += i.size();
146
572
        }
147
274
        _nums.resize(rows);
148
274
        size_t count = 0;
149
150
274
        std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap;
151
846
        for (int i = 0; i < _sorted_nums_vec.size(); ++i) {
152
572
            if (!_sorted_nums_vec[i].empty()) {
153
572
                min_heap.emplace(_sorted_nums_vec[i][0], i, 0);
154
572
            }
155
572
        }
156
157
1.00k
        while (!min_heap.empty()) {
158
729
            Node node = min_heap.top();
159
729
            min_heap.pop();
160
729
            _nums[count++] = node.value;
161
729
            if (++node.element_index < _sorted_nums_vec[node.array_index].size()) {
162
157
                node.value = _sorted_nums_vec[node.array_index][node.element_index];
163
157
                min_heap.push(node);
164
157
            }
165
729
        }
166
274
        _sorted_nums_vec.clear();
167
274
    }
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
118
    void _convert_sorted_num_vec_to_nums() {
143
118
        size_t rows = 0;
144
233
        for (const auto& i : _sorted_nums_vec) {
145
233
            rows += i.size();
146
233
        }
147
118
        _nums.resize(rows);
148
118
        size_t count = 0;
149
150
118
        std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap;
151
351
        for (int i = 0; i < _sorted_nums_vec.size(); ++i) {
152
233
            if (!_sorted_nums_vec[i].empty()) {
153
233
                min_heap.emplace(_sorted_nums_vec[i][0], i, 0);
154
233
            }
155
233
        }
156
157
472
        while (!min_heap.empty()) {
158
354
            Node node = min_heap.top();
159
354
            min_heap.pop();
160
354
            _nums[count++] = node.value;
161
354
            if (++node.element_index < _sorted_nums_vec[node.array_index].size()) {
162
121
                node.value = _sorted_nums_vec[node.array_index][node.element_index];
163
121
                min_heap.push(node);
164
121
            }
165
354
        }
166
118
        _sorted_nums_vec.clear();
167
118
    }
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
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
13
            std::priority_queue<Node> max_heap;
174
54
            for (int i = 0; i < _sorted_nums_vec.size(); ++i) {
175
41
                if (!_sorted_nums_vec[i].empty()) {
176
41
                    max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i,
177
41
                                     _sorted_nums_vec[i].size() - 1);
178
41
                }
179
41
            }
180
181
45
            while (!max_heap.empty()) {
182
45
                Node node = max_heap.top();
183
45
                max_heap.pop();
184
45
                if (count == target) {
185
13
                    second_number = node.value;
186
32
                } else if (count == target + 1) {
187
13
                    first_number = node.value;
188
13
                    break;
189
13
                }
190
32
                ++count;
191
32
                if (--node.element_index >= 0) {
192
27
                    node.value = _sorted_nums_vec[node.array_index][node.element_index];
193
27
                    max_heap.push(node);
194
27
                }
195
32
            }
196
197
13
        } else {
198
8
            std::priority_queue<Node, std::vector<Node>, std::greater<Node>> min_heap;
199
24
            for (int i = 0; i < _sorted_nums_vec.size(); ++i) {
200
16
                if (!_sorted_nums_vec[i].empty()) {
201
16
                    min_heap.emplace(_sorted_nums_vec[i][0], i, 0);
202
16
                }
203
16
            }
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
8
                    first_number = node.value;
210
20
                } else if (count == target + 1) {
211
8
                    second_number = node.value;
212
8
                    break;
213
8
                }
214
20
                ++count;
215
20
                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
20
            }
220
8
        }
221
222
21
        return {first_number, second_number};
223
21
    }
_ZN5doris6CountsIaE27_merge_sort_and_get_numbersElb
Line
Count
Source
169
2
    std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) {
170
2
        Ty first_number = 0, second_number = 0;
171
2
        size_t count = 0;
172
2
        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
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
2
        return {first_number, second_number};
223
2
    }
_ZN5doris6CountsIsE27_merge_sort_and_get_numbersElb
Line
Count
Source
169
2
    std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) {
170
2
        Ty first_number = 0, second_number = 0;
171
2
        size_t count = 0;
172
2
        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
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
2
        return {first_number, second_number};
223
2
    }
_ZN5doris6CountsIiE27_merge_sort_and_get_numbersElb
Line
Count
Source
169
2
    std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) {
170
2
        Ty first_number = 0, second_number = 0;
171
2
        size_t count = 0;
172
2
        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
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
2
        return {first_number, second_number};
223
2
    }
_ZN5doris6CountsIlE27_merge_sort_and_get_numbersElb
Line
Count
Source
169
9
    std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) {
170
9
        Ty first_number = 0, second_number = 0;
171
9
        size_t count = 0;
172
9
        if (reverse) {
173
7
            std::priority_queue<Node> max_heap;
174
36
            for (int i = 0; i < _sorted_nums_vec.size(); ++i) {
175
29
                if (!_sorted_nums_vec[i].empty()) {
176
29
                    max_heap.emplace(_sorted_nums_vec[i][_sorted_nums_vec[i].size() - 1], i,
177
29
                                     _sorted_nums_vec[i].size() - 1);
178
29
                }
179
29
            }
180
181
33
            while (!max_heap.empty()) {
182
33
                Node node = max_heap.top();
183
33
                max_heap.pop();
184
33
                if (count == target) {
185
7
                    second_number = node.value;
186
26
                } else if (count == target + 1) {
187
7
                    first_number = node.value;
188
7
                    break;
189
7
                }
190
26
                ++count;
191
26
                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
26
            }
196
197
7
        } 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
10
            while (!min_heap.empty()) {
206
10
                Node node = min_heap.top();
207
10
                min_heap.pop();
208
10
                if (count == target) {
209
2
                    first_number = node.value;
210
8
                } else if (count == target + 1) {
211
2
                    second_number = node.value;
212
2
                    break;
213
2
                }
214
8
                ++count;
215
8
                if (++node.element_index < _sorted_nums_vec[node.array_index].size()) {
216
7
                    node.value = _sorted_nums_vec[node.array_index][node.element_index];
217
7
                    min_heap.push(node);
218
7
                }
219
8
            }
220
2
        }
221
222
9
        return {first_number, second_number};
223
9
    }
_ZN5doris6CountsInE27_merge_sort_and_get_numbersElb
Line
Count
Source
169
2
    std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) {
170
2
        Ty first_number = 0, second_number = 0;
171
2
        size_t count = 0;
172
2
        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
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
2
        return {first_number, second_number};
223
2
    }
_ZN5doris6CountsIfE27_merge_sort_and_get_numbersElb
Line
Count
Source
169
2
    std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) {
170
2
        Ty first_number = 0, second_number = 0;
171
2
        size_t count = 0;
172
2
        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
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
2
        return {first_number, second_number};
223
2
    }
_ZN5doris6CountsIdE27_merge_sort_and_get_numbersElb
Line
Count
Source
169
2
    std::pair<Ty, Ty> _merge_sort_and_get_numbers(int64_t target, bool reverse) {
170
2
        Ty first_number = 0, second_number = 0;
171
2
        size_t count = 0;
172
2
        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
0
                    node.value = _sorted_nums_vec[node.array_index][node.element_index];
193
0
                    max_heap.push(node);
194
0
                }
195
1
            }
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
2
        return {first_number, second_number};
223
2
    }
224
225
    vectorized::PODArray<Ty> _nums;
226
    std::vector<vectorized::PODArray<Ty>> _sorted_nums_vec;
227
};
228
229
} // namespace doris