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

#include "copy_multi_value_read_view.h"

using vespalib::datastore::AtomicEntryRef;

namespace search::attribute {

template <typename MultiValueType, typename RawMultiValueType>
CopyMultiValueReadView<MultiValueType, RawMultiValueType>::CopyMultiValueReadView(MultiValueMappingReadView<RawMultiValueType> mv_mapping_read_view)
    : _mv_mapping_read_view(mv_mapping_read_view),
      _copy()
{
}

template <typename MultiValueType, typename RawMultiValueType>
CopyMultiValueReadView<MultiValueType, RawMultiValueType>::~CopyMultiValueReadView() = default;

template <typename MultiValueType, typename RawMultiValueType>
vespalib::ConstArrayRef<MultiValueType>
CopyMultiValueReadView<MultiValueType, RawMultiValueType>::get_values(uint32_t docid) const
{
    auto raw = _mv_mapping_read_view.get(docid);
    if (_copy.size() < raw.size()) {
        _copy.resize(raw.size());
    }
    auto dst = _copy.data();
    for (auto &src : raw) {
        ValueType v = multivalue::get_value_ref(src);
        *dst = multivalue::ValueBuilder<MultiValueType>::build(v, multivalue::get_weight(src));
        ++dst;
    }
    return vespalib::ConstArrayRef(_copy.data(), raw.size());
}

using multivalue::WeightedValue;

template class CopyMultiValueReadView<int8_t, WeightedValue<int8_t>>;
template class CopyMultiValueReadView<int16_t, WeightedValue<int16_t>>;
template class CopyMultiValueReadView<int32_t, WeightedValue<int32_t>>;
template class CopyMultiValueReadView<int64_t, WeightedValue<int64_t>>;
template class CopyMultiValueReadView<float, WeightedValue<float>>;
template class CopyMultiValueReadView<double, WeightedValue<double>>;
template class CopyMultiValueReadView<AtomicEntryRef, WeightedValue<AtomicEntryRef>>;

template class CopyMultiValueReadView<WeightedValue<int8_t>, int8_t>;
template class CopyMultiValueReadView<WeightedValue<int16_t>, int16_t>;
template class CopyMultiValueReadView<WeightedValue<int32_t>, int32_t>;
template class CopyMultiValueReadView<WeightedValue<int64_t>, int64_t>;
template class CopyMultiValueReadView<WeightedValue<float>, float>;
template class CopyMultiValueReadView<WeightedValue<double>, double>;
template class CopyMultiValueReadView<WeightedValue<AtomicEntryRef>, AtomicEntryRef>;

}