• 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

79.25
/src/realm/array_integer.hpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 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_HPP
20
#define REALM_ARRAY_INTEGER_HPP
21

22
#include <realm/array.hpp>
23
#include <realm/util/safe_int_ops.hpp>
24
#include <realm/util/optional.hpp>
25
#include <realm/array_key.hpp>
26

27
namespace realm {
28

29
class ArrayInteger : public Array, public ArrayPayload {
30
public:
31
    using value_type = int64_t;
32

33
    using Array::add;
34
    using Array::find_first;
35
    using Array::get;
36
    using Array::insert;
37
    using Array::move;
38
    using Array::set;
39

40
    explicit ArrayInteger(Allocator&) noexcept;
41
    ~ArrayInteger() noexcept override {}
93,869,814✔
42

43
    static value_type default_value(bool)
44
    {
24,046,269✔
45
        return 0;
24,046,269✔
46
    }
24,046,269✔
47

48
    void init_from_ref(ref_type ref) noexcept override
49
    {
27,061,452✔
50
        Array::init_from_ref(ref);
27,061,452✔
51
    }
27,061,452✔
52
    void set_parent(ArrayParent* parent, size_t ndx_in_parent) noexcept override
53
    {
91,002,762✔
54
        Array::set_parent(parent, ndx_in_parent);
91,002,762✔
55
    }
91,002,762✔
56

57
    // Disable copying, this is not allowed.
58
    ArrayInteger& operator=(const ArrayInteger&) = delete;
59
    ArrayInteger(const ArrayInteger&) = delete;
60

61
    void create()
62
    {
576,285✔
63
        Array::create(type_Normal, false, 0, 0);
576,285✔
64
    }
576,285✔
65
    Mixed get_any(size_t ndx) const override;
66

67
    bool is_null(size_t) const
UNCOV
68
    {
×
UNCOV
69
        return false;
×
UNCOV
70
    }
×
71
    template <class cond>
72
    bool find(value_type value, size_t start, size_t end, QueryStateBase* state) const;
73

74
    size_t find_first_in_range(int64_t from, int64_t to, size_t start, size_t end) const;
75
};
76

77
class ArrayIntNull : public Array, public ArrayPayload {
78
public:
79
    using value_type = util::Optional<int64_t>;
80

81
    explicit ArrayIntNull(Allocator&) noexcept;
82
    ~ArrayIntNull() noexcept override;
83

84
    static value_type default_value(bool nullable)
85
    {
2,433,687✔
86
        return nullable ? util::none : util::Optional<int64_t>(0);
2,433,687✔
87
    }
2,433,687✔
88

89
    /// Construct an array of the specified type and size, and return just the
90
    /// reference to the underlying memory. All elements will be initialized to
91
    /// the specified value.
92
    static MemRef create_array(Type, bool context_flag, size_t size, Allocator&);
93
    void create()
94
    {
45,363✔
95
        MemRef r = create_array(type_Normal, false, 0, m_alloc);
45,363✔
96
        init_from_mem(r);
45,363✔
97
    }
45,363✔
98

99
    void init_from_ref(ref_type) noexcept override;
100
    void set_parent(ArrayParent* parent, size_t ndx_in_parent) noexcept override
101
    {
10,892,601✔
102
        Array::set_parent(parent, ndx_in_parent);
10,892,601✔
103
    }
10,892,601✔
104
    void init_from_mem(MemRef) noexcept;
105
    void init_from_parent() noexcept;
106

107
    size_t size() const noexcept;
108
    bool is_empty() const noexcept;
109

110
    void insert(size_t ndx, value_type value);
111
    void add(value_type value);
112
    void set(size_t ndx, value_type value);
113
    value_type get(size_t ndx) const noexcept;
114
    Mixed get_any(size_t ndx) const override;
115
    static value_type get(const char* header, size_t ndx) noexcept;
116
    void get_chunk(size_t ndx, value_type res[8]) const noexcept;
117
    void set_null(size_t ndx);
118
    bool is_null(size_t ndx) const noexcept;
119
    int64_t null_value() const noexcept;
120

121
    void erase(size_t ndx);
122
    void erase(size_t begin, size_t end);
123
    void move(ArrayIntNull& dst, size_t ndx);
124
    void clear();
125

126
    void move(size_t begin, size_t end, size_t dest_begin);
127

128
    bool find(int cond, value_type value, size_t start, size_t end, QueryStateBase* state) const;
129

130
    template <class cond>
131
    bool find(value_type value, size_t start, size_t end, QueryStateBase* state) const;
132

133
    // Wrappers for backwards compatibility and for simple use without
134
    // setting up state initialization etc
135
    template <class cond>
136
    size_t find_first(value_type value, size_t start = 0, size_t end = npos) const;
137

138
    void find_all(IntegerColumn* result, value_type value, size_t col_offset = 0, size_t begin = 0,
139
                  size_t end = npos) const;
140

141

142
    size_t find_first(value_type value, size_t begin = 0, size_t end = npos) const;
143
    size_t find_first_in_range(int64_t from, int64_t to, size_t start, size_t end) const;
144

145
protected:
146
    void avoid_null_collision(int64_t value);
147

148
private:
149
    int_fast64_t choose_random_null(int64_t incoming) const;
150
    void replace_nulls_with(int64_t new_null);
151
    bool can_use_as_null(int64_t value) const;
152

153
    bool find_impl(int cond, value_type value, size_t start, size_t end, QueryStateBase* state) const;
154
    template <class cond>
155
    bool find_impl(value_type value, size_t start, size_t end, QueryStateBase* state) const;
156
};
157

158

159
// Implementation:
160

161
inline ArrayInteger::ArrayInteger(Allocator& allocator) noexcept
162
    : Array(allocator)
46,572,378✔
163
{
93,945,045✔
164
    m_is_inner_bptree_node = false;
93,945,045✔
165
}
93,945,045✔
166

167
inline ArrayIntNull::ArrayIntNull(Allocator& allocator) noexcept
168
    : Array(allocator)
43,104,708✔
169
{
87,349,845✔
170
}
87,349,845✔
171

172
inline ArrayIntNull::~ArrayIntNull() noexcept {}
87,361,935✔
173

174
inline size_t ArrayIntNull::size() const noexcept
175
{
3,640,578✔
176
    return Array::size() - 1;
3,640,578✔
177
}
3,640,578✔
178

179
inline bool ArrayIntNull::is_empty() const noexcept
UNCOV
180
{
×
UNCOV
181
    return size() == 0;
×
UNCOV
182
}
×
183

184
inline void ArrayIntNull::insert(size_t ndx, value_type value)
185
{
2,784,606✔
186
    if (value) {
2,784,606✔
187
        avoid_null_collision(*value);
381,828✔
188
        Array::insert(ndx + 1, *value);
381,828✔
189
    }
381,828✔
190
    else {
2,402,778✔
191
        Array::insert(ndx + 1, null_value());
2,402,778✔
192
    }
2,402,778✔
193
}
2,784,606✔
194

195
inline void ArrayIntNull::add(value_type value)
196
{
1,138,578✔
197
    if (value) {
1,138,578✔
198
        avoid_null_collision(*value);
1,136,295✔
199
        Array::add(*value);
1,136,295✔
200
    }
1,136,295✔
201
    else {
2,283✔
202
        Array::add(null_value());
2,283✔
203
    }
2,283✔
204
}
1,138,578✔
205

206
inline void ArrayIntNull::set(size_t ndx, value_type value)
207
{
3,614,451✔
208
    if (value) {
3,614,451✔
209
        avoid_null_collision(*value);
3,614,313✔
210
        Array::set(ndx + 1, *value);
3,614,313✔
211
    }
3,614,313✔
212
    else {
138✔
213
        Array::set(ndx + 1, null_value());
138✔
214
    }
138✔
215
}
3,614,451✔
216

217
inline void ArrayIntNull::set_null(size_t ndx)
218
{
11,466✔
219
    Array::set(ndx + 1, null_value());
11,466✔
220
}
11,466✔
221

222
inline ArrayIntNull::value_type ArrayIntNull::get(size_t ndx) const noexcept
223
{
121,863,030✔
224
    int64_t value = Array::get(ndx + 1);
121,863,030✔
225
    if (value == null_value()) {
121,863,030✔
226
        return util::none;
1,441,401✔
227
    }
1,441,401✔
228
    return util::some<int64_t>(value);
120,421,629✔
229
}
121,863,030✔
230

231
inline ArrayIntNull::value_type ArrayIntNull::get(const char* header, size_t ndx) noexcept
UNCOV
232
{
×
UNCOV
233
    int64_t null_value = Array::get(header, 0);
×
UNCOV
234
    int64_t value = Array::get(header, ndx + 1);
×
235
    if (value == null_value) {
×
236
        return util::none;
×
237
    }
×
238
    else {
×
239
        return util::some<int64_t>(value);
×
240
    }
×
241
}
×
242

243
inline bool ArrayIntNull::is_null(size_t ndx) const noexcept
244
{
13,358,937✔
245
    return !get(ndx);
13,358,937✔
246
}
13,358,937✔
247

248
inline int64_t ArrayIntNull::null_value() const noexcept
249
{
124,571,118✔
250
    return Array::get(0);
124,571,118✔
251
}
124,571,118✔
252

253
inline void ArrayIntNull::erase(size_t ndx)
254
{
1,342,593✔
255
    Array::erase(ndx + 1);
1,342,593✔
256
}
1,342,593✔
257

258
inline void ArrayIntNull::erase(size_t begin, size_t end)
UNCOV
259
{
×
UNCOV
260
    Array::erase(begin + 1, end + 1);
×
UNCOV
261
}
×
262

263
inline void ArrayIntNull::clear()
264
{
552✔
265
    Array::truncate(0);
552✔
266
    Array::add(0);
552✔
267
}
552✔
268

269
inline void ArrayIntNull::move(size_t begin, size_t end, size_t dest_begin)
UNCOV
270
{
×
UNCOV
271
    Array::move(begin + 1, end + 1, dest_begin + 1);
×
UNCOV
272
}
×
273

274
} // namespace realm
275

276
#endif // REALM_ARRAY_INTEGER_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