• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / thomas.goyne_113

27 Oct 2023 10:49AM UTC coverage: 91.596% (+0.03%) from 91.571%
thomas.goyne_113

push

Evergreen

web-flow
Merge pull request #7085 from realm/release/13.23.2

Release/13.23.2

91788 of 168244 branches covered (0.0%)

230165 of 251282 relevant lines covered (91.6%)

6444552.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.31
/src/realm/array_integer_tpl.hpp
1
/*************************************************************************
2
 *
3
 * Copyright 2021 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * 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, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#ifndef REALM_ARRAY_INTEGER_TPL_HPP
20
#define REALM_ARRAY_INTEGER_TPL_HPP
21

22
#include <realm/array_integer.hpp>
23
#include <realm/array_with_find.hpp>
24

25
namespace realm {
26

27
template <class cond, class Callback>
28
bool ArrayInteger::find(value_type value, size_t start, size_t end, QueryStateBase* state, Callback callback) const
29
{
5,090,445✔
30
    return ArrayWithFind(*this).find<cond, Callback>(value, start, end, 0, state, callback);
5,090,445✔
31
}
5,090,445✔
32

33
template <class Callback>
34
inline bool ArrayIntNull::find_impl(int cond, value_type value, size_t start, size_t end, QueryStateBase* state,
×
35
                                    Callback callback) const
×
36
{
×
37
    switch (cond) {
×
38
        case cond_Equal:
×
39
            return find_impl<Equal>(value, start, end, state, callback);
×
40
        case cond_NotEqual:
×
41
            return find_impl<NotEqual>(value, start, end, state, callback);
×
42
        case cond_Greater:
×
43
            return find_impl<Greater>(value, start, end, state, callback);
×
44
        case cond_Less:
×
45
            return find_impl<Less>(value, start, end, state, callback);
×
46
        case cond_None:
×
47
            return find_impl<None>(value, start, end, state, callback);
×
48
        case cond_LeftNotNull:
×
49
            return find_impl<NotNull>(value, start, end, state, callback);
×
50
    }
×
51
    REALM_ASSERT_DEBUG(false);
×
52
    return false;
53
}
54

55
template <class cond, class Callback>
238,497✔
56
bool ArrayIntNull::find_impl(value_type opt_value, size_t start, size_t end, QueryStateBase* state,
238,497✔
57
                             Callback callback) const
238,497✔
58
{
238,497✔
59
    int64_t null_value = Array::get(0);
119,247✔
60
    bool find_null = !bool(opt_value);
226,512✔
61
    int64_t value;
238,497✔
62

238,497✔
63
    size_t end2 = (end == npos ? size() : end) + 1;
119,247✔
64
    size_t start2 = start + 1;
238,497✔
65
    size_t baseindex2 = size_t(-1);
127,785✔
66

7,512✔
67
    if constexpr (std::is_same_v<cond, Equal>) {
7,512✔
68
        if (find_null) {
120,273✔
69
            value = null_value;
120,273✔
70
        }
71
        else {
×
72
            if (*opt_value == null_value) {
×
73
                // If the value to search for is equal to the null value, the value cannot be in the array
120,273✔
74
                return true;
120,273✔
75
            }
120,273✔
76
            else {
120,273✔
77
                value = *opt_value;
55,356✔
78
            }
55,356✔
79
        }
127,785✔
80

127,785✔
81
        // Fall back to plain Array find.
110,712✔
82
        return ArrayWithFind(*this).find<cond>(value, start2, end2, baseindex2, state, callback);
110,712✔
83
    }
55,356✔
84
    else {
110,712!
85
        cond c;
89,796✔
86

89,796✔
87
        if (opt_value) {
20,916✔
88
            value = *opt_value;
20,916✔
89
        }
20,916✔
90
        else {
55,356✔
91
            value = null_value;
18,491,598!
92
        }
18,417,492✔
93

18,417,492✔
94
        for (size_t i = start2; i < end2; ++i) {
18,417,492✔
95
            int64_t v = Array::get(i);
18,381,468✔
96
            bool value_is_null = (v == null_value);
18,381,540✔
97
            if (c(v, value, value_is_null, find_null)) {
36,606✔
98
                util::Optional<int64_t> v2 = value_is_null ? util::none : util::make_optional(v);
36,606✔
99
                if (!ArrayWithFind(*this).find_action(i + baseindex2, v2, state, callback)) {
18,381,540✔
100
                    return false; // tell caller to stop aggregating/search
18,417,492✔
101
                }
92,409✔
102
            }
110,712✔
103
        }
238,497✔
104
        return true; // tell caller to continue aggregating/search (on next array leafs)
105
    }
106
}
107

85,641✔
108
template <class cond>
85,641✔
109
size_t ArrayIntNull::find_first(value_type value, size_t start, size_t end) const
85,641✔
110
{
42,819✔
111
    QueryStateFindFirst state;
85,641✔
112
    find_impl<cond>(value, start, end, &state, nullptr);
48,168✔
113

37,473✔
114
    if (state.match_count() > 0)
37,473✔
115
        return to_size_t(state.m_state);
85,641✔
116
    else
117
        return not_found;
118
}
119

152,856✔
120
template <class cond, class Callback>
152,856✔
121
inline bool ArrayIntNull::find(value_type value, size_t start, size_t end, QueryStateBase* state,
152,856✔
122
                               Callback callback) const
123
{
124
    return find_impl<cond, Callback>(value, start, end, state, callback);
125
}
126

127
} // namespace realm
128

129
#endif /* REALM_ARRAY_INTEGER_TPL_HPP */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc