aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h
blob: 2e27062bbf5c7a4a56400cc7c385a1ef1931fc66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "i_enum_store_dictionary.h"
#include <vespa/vespalib/btree/btree.h>

namespace search {

class IEnumStore;

/**
 * Concrete dictionary for an enum store that extends the functionality of a unique store dictionary.
 */
template <typename BTreeDictionaryT, typename HashDictionaryT = vespalib::datastore::NoHashDictionary>
class EnumStoreDictionary : public vespalib::datastore::UniqueStoreDictionary<BTreeDictionaryT, IEnumStoreDictionary, HashDictionaryT> {
protected:
    using AtomicEntryRef = IEnumStoreDictionary::AtomicEntryRef;
    using EntryRef = IEnumStoreDictionary::EntryRef;
    using EntryRefFilter = IEnumStoreDictionary::EntryRefFilter;
    using Index = IEnumStoreDictionary::Index;
    using BTreeDictionaryType = BTreeDictionaryT;
    using EntryComparator = IEnumStoreDictionary::EntryComparator;
private:
    using EnumVector = IEnumStoreDictionary::EnumVector;
    using IndexList = IEnumStoreDictionary::IndexList;
    using IndexVector = IEnumStoreDictionary::IndexVector;
    using ParentUniqueStoreDictionary = vespalib::datastore::UniqueStoreDictionary<BTreeDictionaryT, IEnumStoreDictionary, HashDictionaryT>;
    using generation_t = IEnumStoreDictionary::generation_t;
protected:
    using ParentUniqueStoreDictionary::has_btree_dictionary;
    using ParentUniqueStoreDictionary::has_hash_dictionary;
private:
    IEnumStore& _enumStore;

    void remove_unused_values(const IndexList& unused, const EntryComparator& cmp);

public:
    EnumStoreDictionary(IEnumStore& enumStore, std::unique_ptr<EntryComparator> compare);

    ~EnumStoreDictionary() override;

    void free_unused_values(const EntryComparator& cmp) override;
    void free_unused_values(const IndexList& to_remove, const EntryComparator& cmp) override;

    void remove(const EntryComparator& comp, EntryRef ref) override;
    bool find_index(const EntryComparator& cmp, Index& idx) const override;
    bool find_frozen_index(const EntryComparator& cmp, Index& idx) const override;
    std::vector<attribute::IAttributeVector::EnumHandle>
    find_matching_enums(const EntryComparator& cmp) const override;

    EntryRef get_frozen_root() const override;
    std::pair<Index, EntryRef> find_posting_list(const EntryComparator& cmp, EntryRef root) const override;
    void collect_folded(Index idx, EntryRef root, const std::function<void(EntryRef)>& callback) const override;
    Index remap_index(Index idx) override;
    void clear_all_posting_lists(std::function<void(EntryRef)> clearer) override;
    void update_posting_list(Index idx, const EntryComparator& cmp, std::function<EntryRef(EntryRef)> updater) override;
    bool normalize_posting_lists(std::function<EntryRef(EntryRef)> normalize) override;
    bool normalize_posting_lists(std::function<void(std::vector<EntryRef>&)> normalize, const EntryRefFilter& filter) override;
    void foreach_posting_list(std::function<void(const std::vector<EntryRef>&)> callback, const EntryRefFilter& filter) override;
    const EnumPostingTree& get_posting_dictionary() const override;
};

/**
 * Concrete dictionary for an enum store that extends the
 * functionality of a unique store dictionary.
 *
 * Special handling of value (posting list reference) is added to
 * ensure that entries with same folded key share a posting list
 * (e.g. case insensitive search) and posting list reference is found
 * for the first of these entries.
 */
class EnumStoreFoldedDictionary : public EnumStoreDictionary<EnumPostingTree>
{
private:
    std::unique_ptr<EntryComparator> _folded_compare;

public:
    EnumStoreFoldedDictionary(IEnumStore& enumStore, std::unique_ptr<EntryComparator> compare, std::unique_ptr<EntryComparator> folded_compare);
    ~EnumStoreFoldedDictionary() override;
    vespalib::datastore::UniqueStoreAddResult add(const EntryComparator& comp, std::function<EntryRef(void)> insertEntry) override;
    void remove(const EntryComparator& comp, EntryRef ref) override;
    void collect_folded(Index idx, EntryRef root, const std::function<void(EntryRef)>& callback) const override;
    Index remap_index(Index idx) override;
};

}

namespace vespalib::btree {

extern template
class BTreeNodeT<datastore::AtomicEntryRef, search::EnumTreeTraits::INTERNAL_SLOTS>;

extern template
class BTreeNodeTT<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated, search::EnumTreeTraits::INTERNAL_SLOTS>;

extern template
class BTreeNodeTT<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeInternalNode<datastore::AtomicEntryRef, NoAggregated, search::EnumTreeTraits::INTERNAL_SLOTS>;

extern template
class BTreeLeafNode<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeLeafNode<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeLeafNodeTemp<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeLeafNodeTemp<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeNodeStore<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                     search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeNodeStore<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                     search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeRoot<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

extern template
class BTreeRoot<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

extern template
class BTreeRootT<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                 const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

extern template
class BTreeRootT<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                 const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

extern template
class BTreeRootBase<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                    search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeRootBase<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                    search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeNodeAllocator<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                         search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS>;

extern template
class BTreeNodeAllocator<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                         search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS>;


extern template
class BTreeIteratorBase<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                        search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS, search::EnumTreeTraits::PATH_SIZE>;
extern template
class BTreeIteratorBase<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                        search::EnumTreeTraits::INTERNAL_SLOTS, search::EnumTreeTraits::LEAF_SLOTS, search::EnumTreeTraits::PATH_SIZE>;

extern template class BTreeConstIterator<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                                         const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

extern template class BTreeConstIterator<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                                         const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

extern template
class BTreeIterator<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
                    const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;
extern template
class BTreeIterator<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
                    const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

extern template
class BTree<datastore::AtomicEntryRef, BTreeNoLeafData, NoAggregated,
            const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;
extern template
class BTree<datastore::AtomicEntryRef, datastore::AtomicEntryRef, NoAggregated,
            const datastore::EntryComparatorWrapper, search::EnumTreeTraits>;

}