blob: d7cd75c3a4074127170183c73437d5a9131d83f7 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "unique_store_enumerator.h"
#include "bufferstate.h"
#include "datastorebase.h"
namespace vespalib::datastore {
template <typename RefT>
UniqueStoreEnumerator<RefT>::UniqueStoreEnumerator(const IUniqueStoreDictionary &dict, DataStoreBase &store, bool sort_unique_values)
: _dict_snapshot(dict.get_read_snapshot()),
_store(store),
_enumValues(),
_next_enum_val(1)
{
_dict_snapshot->fill();
if (sort_unique_values) {
_dict_snapshot->sort();
}
allocate_enum_values(store);
}
template <typename RefT>
UniqueStoreEnumerator<RefT>::~UniqueStoreEnumerator() = default;
template <typename RefT>
void
UniqueStoreEnumerator<RefT>::enumerateValue(EntryRef ref)
{
RefType iRef(ref);
assert(iRef.valid());
assert(iRef.offset() < _enumValues[iRef.bufferId()].size());
uint32_t &enumVal = _enumValues[iRef.bufferId()][iRef.offset()];
assert(enumVal == 0u);
enumVal = _next_enum_val;
++_next_enum_val;
}
template <typename RefT>
void
UniqueStoreEnumerator<RefT>::allocate_enum_values(DataStoreBase & store)
{
_enumValues.resize(store.get_bufferid_limit_relaxed());
store.for_each_active_buffer([this](uint32_t buffer_id, const BufferState & state) {
_enumValues[buffer_id].resize(state.size());
});
}
template <typename RefT>
void
UniqueStoreEnumerator<RefT>::enumerateValues()
{
_next_enum_val = 1;
_dict_snapshot->foreach_key([this](const AtomicEntryRef& ref) noexcept { enumerateValue(ref.load_acquire()); });
}
template <typename RefT>
void
UniqueStoreEnumerator<RefT>::clear()
{
EnumValues().swap(_enumValues);
}
}
|