• 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

78.85
/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 {}
65,641,596✔
42

43
    static value_type default_value(bool)
44
    {
23,856,171✔
45
        return 0;
23,856,171✔
46
    }
23,856,171✔
47

48
    void init_from_ref(ref_type ref) noexcept override
49
    {
14,998,032✔
50
        Array::init_from_ref(ref);
14,998,032✔
51
    }
14,998,032✔
52
    void set_parent(ArrayParent* parent, size_t ndx_in_parent) noexcept override
53
    {
71,589,591✔
54
        Array::set_parent(parent, ndx_in_parent);
71,589,591✔
55
    }
71,589,591✔
56

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

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

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

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

79
    explicit ArrayIntNull(Allocator&) noexcept;
80
    ~ArrayIntNull() noexcept override;
81

82
    static value_type default_value(bool nullable)
83
    {
1,550,619✔
84
        return nullable ? util::none : util::Optional<int64_t>(0);
1,475,742✔
85
    }
1,550,619✔
86

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

97
    void init_from_ref(ref_type) noexcept override;
98
    void set_parent(ArrayParent* parent, size_t ndx_in_parent) noexcept override
99
    {
9,858,711✔
100
        Array::set_parent(parent, ndx_in_parent);
9,858,711✔
101
    }
9,858,711✔
102
    void init_from_mem(MemRef) noexcept;
103
    void init_from_parent() noexcept;
104

105
    size_t size() const noexcept;
106
    bool is_empty() const noexcept;
107

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

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

124
    void move(size_t begin, size_t end, size_t dest_begin);
125

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

128
    template <class cond, class Callback>
129
    bool find(value_type value, size_t start, size_t end, QueryStateBase* state, Callback callback) const;
130

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

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

139

140
    size_t find_first(value_type value, size_t begin = 0, size_t end = npos) const;
141

142
protected:
143
    void avoid_null_collision(int64_t value);
144

145
private:
146
    int_fast64_t choose_random_null(int64_t incoming) const;
147
    void replace_nulls_with(int64_t new_null);
148
    bool can_use_as_null(int64_t value) const;
149

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

157

158
// Implementation:
159

160
inline ArrayInteger::ArrayInteger(Allocator& allocator) noexcept
65,517,843✔
161
    : Array(allocator)
65,517,843✔
162
{
65,517,843✔
163
    m_is_inner_bptree_node = false;
164
}
165

166
inline ArrayIntNull::ArrayIntNull(Allocator& allocator) noexcept
80,654,190✔
167
    : Array(allocator)
80,654,190✔
168
{
169
}
80,667,744✔
170

171
inline ArrayIntNull::~ArrayIntNull() noexcept {}
172

2,876,874✔
173
inline size_t ArrayIntNull::size() const noexcept
2,876,874✔
174
{
2,876,874✔
175
    return Array::size() - 1;
176
}
177

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

1,885,986✔
183
inline void ArrayIntNull::insert(size_t ndx, value_type value)
1,885,986✔
184
{
370,317✔
185
    if (value) {
370,317✔
186
        avoid_null_collision(*value);
370,317✔
187
        Array::insert(ndx + 1, *value);
1,515,669✔
188
    }
1,515,669✔
189
    else {
1,515,669✔
190
        Array::insert(ndx + 1, null_value());
1,885,986✔
191
    }
192
}
193

1,144,788✔
194
inline void ArrayIntNull::add(value_type value)
1,144,788✔
195
{
1,128,792✔
196
    if (value) {
1,128,792✔
197
        avoid_null_collision(*value);
1,128,792✔
198
        Array::add(*value);
15,996✔
199
    }
15,996✔
200
    else {
15,996✔
201
        Array::add(null_value());
1,144,788✔
202
    }
203
}
204

2,700,762✔
205
inline void ArrayIntNull::set(size_t ndx, value_type value)
2,700,762✔
206
{
2,700,627✔
207
    if (value) {
2,700,627✔
208
        avoid_null_collision(*value);
2,700,627✔
209
        Array::set(ndx + 1, *value);
135✔
210
    }
135✔
211
    else {
135✔
212
        Array::set(ndx + 1, null_value());
2,700,762✔
213
    }
214
}
215

12,426✔
216
inline void ArrayIntNull::set_null(size_t ndx)
12,426✔
217
{
12,426✔
218
    Array::set(ndx + 1, null_value());
219
}
220

79,023,678✔
221
inline ArrayIntNull::value_type ArrayIntNull::get(size_t ndx) const noexcept
79,023,678✔
222
{
79,023,678✔
223
    int64_t value = Array::get(ndx + 1);
1,647,411✔
224
    if (value == null_value()) {
1,647,411✔
225
        return util::none;
77,376,267✔
226
    }
77,376,267✔
227
    return util::some<int64_t>(value);
228
}
229

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

1,517,595✔
242
inline bool ArrayIntNull::is_null(size_t ndx) const noexcept
1,517,595✔
243
{
1,517,595✔
244
    return !get(ndx);
245
}
246

80,848,767✔
247
inline int64_t ArrayIntNull::null_value() const noexcept
80,848,767✔
248
{
80,848,767✔
249
    return Array::get(0);
250
}
251

1,356,234✔
252
inline void ArrayIntNull::erase(size_t ndx)
1,356,234✔
253
{
1,356,234✔
254
    Array::erase(ndx + 1);
255
}
256

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

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

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

273
} // namespace realm
274

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

© 2025 Coveralls, Inc