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

realm / realm-core / jorgen.edelbo_391

13 Aug 2024 07:57AM UTC coverage: 91.091% (-0.02%) from 91.107%
jorgen.edelbo_391

Pull #7826

Evergreen

web-flow
Merge pull request #7979 from realm/test-upgrade-files

Create test file in file-format 24
Pull Request #7826: Merge Next major

103486 of 182216 branches covered (56.79%)

3157 of 3519 new or added lines in 54 files covered. (89.71%)

191 existing lines in 22 files now uncovered.

219971 of 241486 relevant lines covered (91.09%)

6652643.8 hits per line

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

88.24
/src/realm/integer_compressor.hpp
1
/*************************************************************************
2
 *
3
 * Copyright 2023 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_INTEGER_COMPRESSOR_HPP
20
#define REALM_INTEGER_COMPRESSOR_HPP
21

22
#include <cstdint>
23
#include <cstddef>
24
#include <vector>
25
#include <realm/query_conditions.hpp>
26
#include <realm/array_direct.hpp>
27
#include <realm/node.hpp>
28

29
namespace realm {
30

31
class Array;
32
class QueryStateBase;
33
class IntegerCompressor {
34
public:
35
    // commit => encode, COW/insert => decode
36
    bool compress(const Array&, Array&) const;
37
    bool decompress(Array&) const;
38

39
    bool init(const char*);
40
    void set_vtable(Array&);
41

42
    // init from mem B
43
    inline uint64_t* data() const;
44
    inline size_t size() const;
45
    inline NodeHeader::Encoding get_encoding() const;
46
    inline uint8_t v_width() const;
47
    inline uint8_t ndx_width() const;
48
    inline size_t v_size() const;
49
    inline size_t ndx_size() const;
50

51
    inline uint64_t v_mask() const;
52
    inline uint64_t ndx_mask() const;
53
    inline uint64_t msb() const;
54
    inline uint64_t ndx_msb() const;
55
    inline uint64_t bitmask_v() const;
56
    inline uint64_t bitmask_ndx() const;
57

58
    int64_t get(size_t) const;
59

60
private:
61
    // getting and setting interface specifically for encoding formats
62
    inline void init_packed(const char*);
63
    inline void init_flex(const char*);
64

65
    static int64_t get_packed(const Array& arr, size_t ndx);
66
    static int64_t get_flex(const Array& arr, size_t ndx);
67

68
    static std::vector<int64_t> get_all_packed(const Array& arr, size_t begin, size_t end);
69
    static std::vector<int64_t> get_all_flex(const Array& arr, size_t begin, size_t end);
70

71
    static void get_chunk_packed(const Array& arr, size_t ndx, int64_t res[8]);
72
    static void get_chunk_flex(const Array& arr, size_t ndx, int64_t res[8]);
73
    // query interface
74
    template <class Cond>
75
    static bool find_packed(const Array& arr, int64_t val, size_t begin, size_t end, size_t base_index,
76
                            QueryStateBase* st);
77
    template <class Cond>
78
    static bool find_flex(const Array& arr, int64_t val, size_t begin, size_t end, size_t base_index,
79
                          QueryStateBase* st);
80

81
    // internal impl
82
    void compress_values(const Array&, std::vector<int64_t>&, std::vector<unsigned>&) const;
83
    inline bool is_packed() const;
84
    inline bool is_flex() const;
85

86
    // for testing
87
    bool always_compress(const Array&, Array&, Node::Encoding) const;
88

89
private:
90
    using Encoding = NodeHeader::Encoding;
91
    Encoding m_encoding{NodeHeader::Encoding::WTypBits};
92
    uint64_t* m_data;
93
    uint8_t m_v_width = 0, m_ndx_width = 0;
94
    size_t m_v_size = 0, m_ndx_size = 0;
95
};
96

97
inline void IntegerCompressor::init_packed(const char* h)
98
{
44,335,086✔
99
    m_data = (uint64_t*)NodeHeader::get_data_from_header(h);
44,335,086✔
100
    m_v_width = NodeHeader::get_element_size(h, Encoding::Packed);
44,335,086✔
101
    m_v_size = NodeHeader::get_num_elements(h, Encoding::Packed);
44,335,086✔
102
}
44,335,086✔
103

104
inline void IntegerCompressor::init_flex(const char* h)
105
{
229,623✔
106
    m_data = (uint64_t*)NodeHeader::get_data_from_header(h);
229,623✔
107
    m_v_width = NodeHeader::get_elementA_size(h);
229,623✔
108
    m_v_size = NodeHeader::get_arrayA_num_elements(h);
229,623✔
109
    m_ndx_width = NodeHeader::get_elementB_size(h);
229,623✔
110
    m_ndx_size = NodeHeader::get_arrayB_num_elements(h);
229,623✔
111
}
229,623✔
112

113
inline uint64_t* IntegerCompressor::data() const
114
{
69,058,218✔
115
    return m_data;
69,058,218✔
116
}
69,058,218✔
117

118
inline bool IntegerCompressor::is_packed() const
119
{
1,218,486,594✔
120
    return m_encoding == NodeHeader::Encoding::Packed;
1,218,486,594✔
121
}
1,218,486,594✔
122

123
inline bool IntegerCompressor::is_flex() const
124
{
877,075,443✔
125
    return m_encoding == NodeHeader::Encoding::Flex;
877,075,443✔
126
}
877,075,443✔
127

128
inline size_t IntegerCompressor::size() const
129
{
5,336,082✔
130
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
5,336,082✔
131
    return m_encoding == NodeHeader::Encoding::Packed ? v_size() : ndx_size();
2,150,482,333✔
132
}
5,336,082✔
133

134
inline size_t IntegerCompressor::v_size() const
135
{
9,423,258✔
136
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
9,423,258✔
137
    return m_v_size;
9,423,258✔
138
}
9,423,258✔
139

140
inline size_t IntegerCompressor::ndx_size() const
141
{
207,090✔
142
    REALM_ASSERT_DEBUG(is_flex());
207,090✔
143
    return m_ndx_size;
207,090✔
144
}
207,090✔
145

146
inline uint8_t IntegerCompressor::v_width() const
147
{
142,590,045✔
148
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
142,590,045✔
149
    return m_v_width;
142,590,045✔
150
}
142,590,045✔
151

152
inline uint8_t IntegerCompressor::ndx_width() const
153
{
4,347,654✔
154
    REALM_ASSERT_DEBUG(is_flex());
4,347,654✔
155
    return m_ndx_width;
4,347,654✔
156
}
4,347,654✔
157

158
inline NodeHeader::Encoding IntegerCompressor::get_encoding() const
159
{
988,921,569✔
160
    return m_encoding;
988,921,569✔
161
}
988,921,569✔
162

163
inline uint64_t IntegerCompressor::v_mask() const
164
{
88,677,099✔
165
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
88,677,099✔
166
    return 1ULL << (m_v_width - 1);
88,677,099✔
167
}
88,677,099✔
168

169
inline uint64_t IntegerCompressor::ndx_mask() const
170
{
8,886✔
171
    REALM_ASSERT_DEBUG(is_flex());
8,886✔
172
    return 1ULL << (m_ndx_width - 1);
8,886✔
173
}
8,886✔
174

175
inline uint64_t IntegerCompressor::msb() const
176
{
3,867,486✔
177
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
3,867,486✔
178
    return populate(m_v_width, v_mask());
3,867,486✔
179
}
3,867,486✔
180

181
inline uint64_t IntegerCompressor::ndx_msb() const
182
{
8,886✔
183
    REALM_ASSERT_DEBUG(is_flex());
8,886✔
184
    return populate(m_ndx_width, ndx_mask());
8,886✔
185
}
8,886✔
186

187
inline uint64_t IntegerCompressor::bitmask_v() const
NEW
188
{
×
NEW
189
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
×
NEW
190
    return 0xFFFFFFFFFFFFFFFFULL >> (64 - m_v_width);
×
NEW
191
}
×
192

193
inline uint64_t IntegerCompressor::bitmask_ndx() const
NEW
194
{
×
NEW
195
    REALM_ASSERT_DEBUG(is_flex());
×
NEW
196
    return 0xFFFFFFFFFFFFFFFFULL >> (64 - m_ndx_width);
×
NEW
197
}
×
198

199
} // namespace realm
200
#endif // REALM_INTEGER_COMPRESSOR_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