summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/multi_value_mapping.hpp
blob: 339f562757de5586fd1f2ce4c73ab183188ca390 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "multi_value_mapping.h"
#include <vespa/vespalib/datastore/array_store.hpp>
#include <vespa/vespalib/util/rcuvector.hpp>

namespace search::attribute {

template <typename EntryT, typename RefT>
MultiValueMapping<EntryT,RefT>::MultiValueMapping(const vespalib::datastore::ArrayStoreConfig &storeCfg,
                                                  const vespalib::GrowStrategy &gs)
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wuninitialized"
#endif
    : MultiValueMappingBase(gs, _store.getGenerationHolder()),
#ifdef __clang__
#pragma clang diagnostic pop
#endif
      _store(storeCfg, {})
{
}

template <typename EntryT, typename RefT>
MultiValueMapping<EntryT,RefT>::~MultiValueMapping() = default;

template <typename EntryT, typename RefT>
void
MultiValueMapping<EntryT,RefT>::set(uint32_t docId, ConstArrayRef values)
{
    _indices.ensure_size(docId + 1);
    EntryRef oldRef(_indices[docId]);
    ConstArrayRef oldValues = _store.get(oldRef);
    _indices[docId] = _store.add(values);
    updateValueCount(oldValues.size(), values.size());
    _store.remove(oldRef);
}

template <typename EntryT, typename RefT>
void
MultiValueMapping<EntryT,RefT>::replace(uint32_t docId, ConstArrayRef values)
{
    auto oldValues = _store.get_writable(_indices[docId]);
    assert(oldValues.size() == values.size());
    EntryT *dst = &oldValues[0];
    for (auto &src : values) {
        *dst = src;
        ++dst;
    }
}

template <typename EntryT, typename RefT>
void
MultiValueMapping<EntryT,RefT>::compactWorst(CompactionSpec compaction_spec, const CompactionStrategy& compaction_strategy)
{
    vespalib::datastore::ICompactionContext::UP compactionContext(_store.compactWorst(compaction_spec, compaction_strategy));
    if (compactionContext) {
        compactionContext->compact(vespalib::ArrayRef<EntryRef>(&_indices[0], _indices.size()));
    }
}

template <typename EntryT, typename RefT>
vespalib::MemoryUsage
MultiValueMapping<EntryT,RefT>::getArrayStoreMemoryUsage() const
{
    return _store.getMemoryUsage();
}

template <typename EntryT, typename RefT>
vespalib::AddressSpace
MultiValueMapping<EntryT, RefT>::getAddressSpaceUsage() const {
    return _store.addressSpaceUsage();
}

template <typename EntryT, typename RefT>
vespalib::datastore::ArrayStoreConfig
MultiValueMapping<EntryT, RefT>::optimizedConfigForHugePage(size_t maxSmallArraySize,
                                                             size_t hugePageSize,
                                                             size_t smallPageSize,
                                                             size_t minNumArraysForNewBuffer,
                                                             float allocGrowFactor,
                                                             bool enable_free_lists)
{
    auto result = ArrayStore::optimizedConfigForHugePage(maxSmallArraySize, hugePageSize, smallPageSize, minNumArraysForNewBuffer, allocGrowFactor);
    result.enable_free_lists(enable_free_lists);
    return result;
}

}