blob: 4182e1452b8fd8e3c034088e8a24639dc3a5ec90 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "streamed_value_index.h"
#include <vespa/eval/eval/value_type.h>
#include <vespa/eval/eval/value.h>
#include <vespa/vespalib/util/shared_string_repo.h>
#include <cassert>
namespace vespalib::eval {
/**
* A very simple Value implementation.
* Cheap to construct from serialized data,
* and cheap to serialize or iterate through.
* Slow for full or partial lookups.
**/
template <typename T>
class StreamedValue : public Value
{
private:
using Handles = SharedStringRepo::Handles;
ValueType _type;
std::vector<T> _my_cells;
Handles _my_labels;
StreamedValueIndex _my_index;
public:
StreamedValue(ValueType type, size_t num_mapped_dimensions,
std::vector<T> cells, size_t num_subspaces, Handles && handles)
: _type(std::move(type)),
_my_cells(std::move(cells)),
_my_labels(std::move(handles)),
_my_index(num_mapped_dimensions,
num_subspaces,
_my_labels.view())
{
assert(num_subspaces * _type.dense_subspace_size() == _my_cells.size());
}
~StreamedValue();
const ValueType &type() const final override { return _type; }
TypedCells cells() const final override { return TypedCells(_my_cells); }
const Value::Index &index() const final override { return _my_index; }
MemoryUsage get_memory_usage() const final override;
};
} // namespace
|