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

realm / realm-core / jorgen.edelbo_322

20 Jun 2024 09:43AM UTC coverage: 84.879% (-6.1%) from 90.966%
jorgen.edelbo_322

Pull #7826

Evergreen

jedelbo
remove set_direct methods from integer compressors
Pull Request #7826: Merge Next major

66056 of 81292 branches covered (81.26%)

3131 of 3738 new or added lines in 54 files covered. (83.76%)

566 existing lines in 29 files now uncovered.

84791 of 99896 relevant lines covered (84.88%)

15351931.14 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,050,617✔
99
    m_data = (uint64_t*)NodeHeader::get_data_from_header(h);
44,050,617✔
100
    m_v_width = NodeHeader::get_element_size(h, Encoding::Packed);
44,050,617✔
101
    m_v_size = NodeHeader::get_num_elements(h, Encoding::Packed);
44,050,617✔
102
}
44,050,617✔
103

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

113
inline uint64_t* IntegerCompressor::data() const
114
{
68,706,921✔
115
    return m_data;
68,706,921✔
116
}
68,706,921✔
117

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

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

128
inline size_t IntegerCompressor::size() const
129
{
4,714,434✔
130
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
4,714,434✔
131
    return m_encoding == NodeHeader::Encoding::Packed ? v_size() : ndx_size();
2,150,423,878✔
132
}
4,714,434✔
133

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

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

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

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

158
inline NodeHeader::Encoding IntegerCompressor::get_encoding() const
159
{
987,069,573✔
160
    return m_encoding;
987,069,573✔
161
}
987,069,573✔
162

163
inline uint64_t IntegerCompressor::v_mask() const
164
{
86,841,519✔
165
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
86,841,519✔
166
    return 1ULL << (m_v_width - 1);
86,841,519✔
167
}
86,841,519✔
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,855,834✔
177
    REALM_ASSERT_DEBUG(is_packed() || is_flex());
3,855,834✔
178
    return populate(m_v_width, v_mask());
3,855,834✔
179
}
3,855,834✔
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