aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/multi_value_mapping_base.cpp
blob: d8747c433f216884f10f5b3341b1a652cc61ea03 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "multi_value_mapping_base.h"
#include <vespa/vespalib/datastore/compaction_spec.h>
#include <vespa/vespalib/datastore/compaction_strategy.h>
#include <vespa/vespalib/util/array.hpp>
#include <cassert>

namespace search::attribute {

using vespalib::datastore::CompactionStrategy;

MultiValueMappingBase::MultiValueMappingBase(const vespalib::GrowStrategy &gs,
                                             vespalib::GenerationHolder &genHolder,
                                             std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator)
    : _memory_allocator(std::move(memory_allocator)),
      _indices(gs, genHolder, _memory_allocator ? vespalib::alloc::Alloc::alloc_with_allocator(_memory_allocator.get()) : vespalib::alloc::Alloc::alloc()),
      _totalValues(0u)
{
}

MultiValueMappingBase::~MultiValueMappingBase() = default;

void
MultiValueMappingBase::addDoc(uint32_t & docId)
{
    uint32_t retval = _indices.size();
    _indices.push_back(AtomicEntryRef());
    docId = retval;
}

void
MultiValueMappingBase::reserve(uint32_t lidLimit)
{
    _indices.reserve(lidLimit);
}

void
MultiValueMappingBase::shrink(uint32_t docIdLimit)
{
    assert(docIdLimit < _indices.size());
    _indices.shrink(docIdLimit);
}

void
MultiValueMappingBase::clearDocs(uint32_t lidLow, uint32_t lidLimit, std::function<void(uint32_t)> clearDoc)
{
    assert(lidLow <= lidLimit);
    assert(lidLimit <= _indices.size());
    for (uint32_t lid = lidLow; lid < lidLimit; ++lid) {
        if (_indices[lid].load_relaxed().valid()) {
            clearDoc(lid);
        }
    }
}

vespalib::MemoryUsage
MultiValueMappingBase::getMemoryUsage() const
{
    vespalib::MemoryUsage retval = getArrayStoreMemoryUsage();
    retval.merge(_indices.getMemoryUsage());
    return retval;
}

}

namespace vespalib {

template class Array<datastore::AtomicEntryRef>;

}