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

#pragma once

#include <vespa/searchcommon/attribute/i_multi_value_read_view.h>
#include <vespa/vespalib/datastore/atomic_value_wrapper.h>

namespace search::attribute {

/**
 * Multi value read view adapter for imported atributes vectors.
 * Performs lid mapping.
 * @tparam MultiValueType The multi-value type of the data to access.
 */
template <typename MultiValueType>
class ImportedMultiValueReadView : public IMultiValueReadView<MultiValueType>
{
    using AtomicTargetLid = vespalib::datastore::AtomicValueWrapper<uint32_t>;
    using TargetLids = vespalib::ConstArrayRef<AtomicTargetLid>;
    TargetLids                                 _target_lids;
    const IMultiValueReadView<MultiValueType>* _target_read_view;

    uint32_t get_target_lid(uint32_t lid) const {
        // Check range to avoid reading memory beyond end of mapping array
        return lid < _target_lids.size() ? _target_lids[lid].load_acquire() : 0u;
    }
public:
    ImportedMultiValueReadView(TargetLids target_lids, const IMultiValueReadView<MultiValueType>* target_read_view);
    ~ImportedMultiValueReadView() override;
    vespalib::ConstArrayRef<MultiValueType> get_values(uint32_t docid) const override;
};

}