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

realm / realm-core / jorgen.edelbo_402

21 Aug 2024 11:10AM UTC coverage: 91.054% (-0.03%) from 91.085%
jorgen.edelbo_402

Pull #7803

Evergreen

jedelbo
Small fix to Table::typed_write

When writing the realm to a new file from a write transaction,
the Table may be COW so that the top ref is changed. So don't
use the ref that is present in the group when the operation starts.
Pull Request #7803: Feature/string compression

103494 of 181580 branches covered (57.0%)

1929 of 1999 new or added lines in 46 files covered. (96.5%)

695 existing lines in 51 files now uncovered.

220142 of 241772 relevant lines covered (91.05%)

7344461.76 hits per line

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

83.33
/src/realm/string_compressor.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_STRING_COMPRESSOR_HPP
20
#define REALM_STRING_COMPRESSOR_HPP
21

22
#include <realm/array_unsigned.hpp>
23
#include <realm/utilities.hpp>
24
#include <vector>
25

26
using CompressionSymbol = uint16_t;
27
using CompressedString = std::vector<CompressionSymbol>;
28

29
struct CompressedStringView {
30
    CompressionSymbol* data = 0;
31
    uint32_t size = 0;
NEW
32
    CompressedStringView() = default;
×
33
    CompressedStringView(CompressionSymbol* c_ptr, size_t s)
34
        : data(c_ptr)
5,224,917✔
35
        , size(uint32_t(s))
5,224,917✔
36
    {
10,754,364✔
37
    }
10,754,364✔
38
    explicit CompressedStringView(CompressedString& cs)
39
        : data(cs.data())
472,413✔
40
        , size(uint32_t(cs.size()))
472,413✔
41
    {
948,606✔
42
    }
948,606✔
43
    bool operator==(CompressedStringView& other)
44
    {
948,606✔
45
        if (size != other.size)
948,606✔
NEW
46
            return false;
×
47
        for (size_t i = 0; i < size; ++i) {
1,126,210,611✔
48
            if (data[i] != other.data[i])
1,125,262,005✔
NEW
49
                return false;
×
50
        }
1,125,262,005✔
51
        return true;
948,606✔
52
    }
948,606✔
53
};
54

55
namespace realm {
56
class StringCompressor {
57
public:
58
    StringCompressor(Allocator& alloc, Array& parent, size_t index, bool writable);
59
    void refresh(bool writable);
60
    ~StringCompressor();
61

62
    int compare(CompressedStringView& A, CompressedStringView& B);
63
    int compare(StringData sd, CompressedStringView& B);
64

65
    CompressedString compress(StringData, bool learn);
66
    std::string decompress(CompressedStringView& c_str);
67

68
private:
69
    struct SymbolDef {
70
        CompressionSymbol id = 0;
71
        CompressionSymbol expansion_a = 0;
72
        CompressionSymbol expansion_b = 0;
73
    };
74

75
    struct ExpandedSymbolDef {
76
        SymbolDef def;
77
        std::string_view expansion;
78
        // ^ points into storage managed by m_expansion_storage
79
        // we need the following 2 values to facilitate rollback of allocated storage
80
        uint32_t storage_index;  // index into m_expansion_storage
81
        uint32_t storage_offset; // offset into block.
82
    };
83

84
    void rebuild_internal();
85
    void expand_compression_map();
86
    void add_expansion(SymbolDef def);
87
    std::vector<ExpandedSymbolDef> m_symbols; // map from symbol -> symbolpair, 2 elements pr entry
88
    std::vector<SymbolDef> m_compression_map; // perfect hash from symbolpair to its symbol
89

90
    ArrayUnsigned m_data;
91
    constexpr static size_t storage_chunk_size = 4096;
92
    std::vector<std::string> m_expansion_storage;
93
};
94

95
} // namespace realm
96

97
#endif
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