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

realm / realm-core / jorgen.edelbo_390

12 Aug 2024 12:13PM UTC coverage: 91.108% (+0.02%) from 91.085%
jorgen.edelbo_390

Pull #7979

Evergreen

jedelbo
Create test file in file-format 24
Pull Request #7979: Create test file in file-format 24

102766 of 181590 branches covered (56.59%)

19 of 19 new or added lines in 1 file covered. (100.0%)

1020 existing lines in 55 files now uncovered.

217365 of 238579 relevant lines covered (91.11%)

5621116.99 hits per line

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

76.32
/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>
28
bool ArrayInteger::find(value_type value, size_t start, size_t end, QueryStateBase* state) const
29
{
6,058,203✔
30
    return ArrayWithFind(*this).find<cond>(value, start, end, 0, state);
6,058,203✔
31
}
6,058,203✔
32

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

53
template <class cond>
54
bool ArrayIntNull::find_impl(value_type opt_value, size_t start, size_t end, QueryStateBase* state) const
55
{
1,127,706✔
56
    int64_t null_value = Array::get(0);
1,127,706✔
57
    bool find_null = !bool(opt_value);
1,127,706✔
58
    int64_t value;
1,127,706✔
59

60
    size_t end2 = (end == npos ? size() : end) + 1;
1,127,706!
61
    size_t start2 = start + 1;
1,127,706✔
62
    size_t baseindex2 = size_t(-1);
1,127,706✔
63

64
    if constexpr (std::is_same_v<cond, Equal>) {
1,127,706✔
65
        if (find_null) {
1,019,472✔
66
            value = null_value;
7,278✔
67
        }
7,278✔
68
        else {
1,012,194✔
69
            if (*opt_value == null_value) {
1,012,194✔
70
                // If the value to search for is equal to the null value, the value cannot be in the array
71
                return true;
2,691✔
72
            }
2,691✔
73
            else {
1,009,503✔
74
                value = *opt_value;
1,009,503✔
75
            }
1,009,503✔
76
        }
1,012,194✔
77

78
        // Fall back to plain Array find.
79
        return ArrayWithFind(*this).find<cond>(value, start2, end2, baseindex2, state);
1,016,781✔
80
    }
581,205✔
81
    else {
108,234✔
82
        cond c;
108,234✔
83

84
        if (opt_value) {
108,234!
85
            value = *opt_value;
88,350✔
86
        }
88,350✔
87
        else {
19,884✔
88
            value = null_value;
19,884✔
89
        }
19,884✔
90

91
        for (size_t i = start2; i < end2; ++i) {
18,488,964!
92
            int64_t v = Array::get(i);
18,415,074✔
93
            bool value_is_null = (v == null_value);
18,415,074✔
94
            if (c(v, value, value_is_null, find_null)) {
18,415,074!
95
                if (!state->match(i + baseindex2)) {
18,379,278!
96
                    return false; // tell caller to stop aggregating/search
34,344✔
97
                }
34,344✔
98
            }
18,379,278✔
99
        }
18,415,074✔
100
        return true; // tell caller to continue aggregating/search (on next array leafs)
73,890✔
101
    }
108,234✔
102
}
1,127,706✔
103

104
template <class cond>
105
size_t ArrayIntNull::find_first(value_type value, size_t start, size_t end) const
106
{
1,163,037✔
107
    static cond c;
1,163,037✔
108
    REALM_ASSERT(start <= m_size && (end <= m_size || end == size_t(-1)) && start <= end);
1,163,037!
109
    if (end - start == 1) {
1,163,037!
110
        std::optional<int64_t> opt_int = get(start);
183,108✔
111
        return c(opt_int, value, !opt_int, !value) ? start : realm::not_found;
183,108!
112
    }
183,108✔
113

114
    QueryStateFindFirst state;
979,929✔
115
    find_impl<cond>(value, start, end, &state);
979,929✔
116

117
    return static_cast<size_t>(state.m_state);
979,929✔
118
}
1,163,037✔
119

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

126
} // namespace realm
127

128
#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

© 2026 Coveralls, Inc