blob: 7031da70cd819563f0f7da72ea9bbb47dd484447 (
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
|
// 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.h"
#include "postingdata.h"
#include <vespa/vespalib/util/array.h>
namespace vespalib::datastore { class EntryComparator; }
namespace search {
class GrowableBitVector;
/**
* Class representing changes to a posting list for a single value.
*/
template <typename P>
class PostingChange
{
public:
using A = vespalib::Array<P>;
using R = std::vector<uint32_t>;
A _additions;
R _removals;
PostingChange();
~PostingChange();
inline void add(uint32_t docId, int32_t weight);
PostingChange & remove(uint32_t docId) {
_removals.push_back(docId);
return *this;
}
void clear() {
_additions.clear();
_removals.clear();
}
/*
* Remove duplicates in additions and removals vectors, since new
* posting list tree doesn't support duplicate entries.
*/
void removeDups();
};
class EnumIndexMapper
{
public:
virtual ~EnumIndexMapper() { }
virtual IEnumStore::Index map(IEnumStore::Index original) const;
virtual bool hasFold() const { return false; }
};
template <typename WeightedIndex, typename PostingMap>
class PostingChangeComputerT
{
private:
using DocIndices = std::vector<std::pair<uint32_t, std::vector<WeightedIndex>>>;
public:
template <typename MultivalueMapping>
static PostingMap compute(const MultivalueMapping & mvm, const DocIndices & docIndices,
const vespalib::datastore::EntryComparator & compare, const EnumIndexMapper & mapper);
};
template <>
inline void
PostingChange<AttributePosting>::add(uint32_t docId, int32_t weight)
{
(void) weight;
_additions.push_back(AttributePosting(docId,
vespalib::btree::BTreeNoLeafData()));
}
template <>
inline void
PostingChange<AttributeWeightPosting>::add(uint32_t docId, int32_t weight)
{
_additions.push_back(AttributeWeightPosting(docId, weight));
}
} // namespace search
|