Coverage Report

Created: 2026-01-19 10:48

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