summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahooinc.com>2023-04-03 15:48:26 +0200
committerGitHub <noreply@github.com>2023-04-03 15:48:26 +0200
commit9a1b3c4041c2a511b70680f37af244e7acad1bcd (patch)
treedb48f8e122093cd2a4d820c2277989987f13cef1 /vespalib
parent8b01e7c51102866fcb22a44f295ce6c7639b48eb (diff)
parent2c50f4251b9cfaf184d6d870ea8870389f08bb40 (diff)
Merge pull request #26676 from vespa-engine/toregge/use-elemt-as-template-parameter-for-array-store
Use ElemT as template parameter for BufferType, SmallArrayBufferType,
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/datastore/array_store/array_store_test.cpp42
-rw-r--r--vespalib/src/vespa/vespalib/btree/btreestore.h4
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.h16
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.hpp94
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store_simple_type_mapper.h6
-rw-r--r--vespalib/src/vespa/vespalib/datastore/buffer_type.h11
-rw-r--r--vespalib/src/vespa/vespalib/datastore/buffer_type.hpp56
-rw-r--r--vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.h6
-rw-r--r--vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.hpp20
-rw-r--r--vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.h4
-rw-r--r--vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.hpp14
11 files changed, 138 insertions, 135 deletions
diff --git a/vespalib/src/tests/datastore/array_store/array_store_test.cpp b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
index ccc3ab88c31..f1dbb5b132e 100644
--- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp
+++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp
@@ -29,16 +29,16 @@ constexpr float ALLOC_GROW_FACTOR = 0.2;
}
-template <typename TestT, typename EntryT, typename RefT = EntryRefT<19> >
+template <typename TestT, typename ElemT, typename RefT = EntryRefT<19> >
struct ArrayStoreTest : public TestT
{
using EntryRefType = RefT;
- using ArrayStoreType = ArrayStore<EntryT, RefT>;
+ using ArrayStoreType = ArrayStore<ElemT, RefT>;
using LargeArray = typename ArrayStoreType::LargeArray;
using ConstArrayRef = typename ArrayStoreType::ConstArrayRef;
- using EntryVector = std::vector<EntryT>;
- using value_type = EntryT;
- using ReferenceStore = vespalib::hash_map<EntryRef, EntryVector>;
+ using ElemVector = std::vector<ElemT>;
+ using value_type = ElemT;
+ using ReferenceStore = vespalib::hash_map<EntryRef, ElemVector>;
AllocStats stats;
ArrayStoreType store;
@@ -61,11 +61,11 @@ struct ArrayStoreTest : public TestT
add_using_allocate(false)
{}
~ArrayStoreTest() override;
- void assertAdd(const EntryVector &input) {
+ void assertAdd(const ElemVector &input) {
EntryRef ref = add(input);
assertGet(ref, input);
}
- EntryRef add(const EntryVector &input) {
+ EntryRef add(const ElemVector &input) {
EntryRef result;
if (add_using_allocate) {
result = store.allocate(input.size());
@@ -82,16 +82,16 @@ struct ArrayStoreTest : public TestT
refStore.insert(std::make_pair(result, input));
return result;
}
- void assertGet(EntryRef ref, const EntryVector &exp) const {
+ void assertGet(EntryRef ref, const ElemVector &exp) const {
ConstArrayRef act = store.get(ref);
- EXPECT_EQ(exp, EntryVector(act.begin(), act.end()));
+ EXPECT_EQ(exp, ElemVector(act.begin(), act.end()));
}
void remove(EntryRef ref) {
ASSERT_EQ(1u, refStore.count(ref));
store.remove(ref);
refStore.erase(ref);
}
- void remove(const EntryVector &input) {
+ void remove(const ElemVector &input) {
remove(getEntryRef(input));
}
uint32_t getBufferId(EntryRef ref) const {
@@ -121,7 +121,7 @@ struct ArrayStoreTest : public TestT
assertGet(elem.first, elem.second);
}
}
- void assert_ref_reused(const EntryVector& first, const EntryVector& second, bool should_reuse) {
+ void assert_ref_reused(const ElemVector& first, const ElemVector& second, bool should_reuse) {
EntryRef ref1 = add(first);
remove(ref1);
reclaim_memory();
@@ -129,7 +129,7 @@ struct ArrayStoreTest : public TestT
EXPECT_EQ(should_reuse, (ref2 == ref1));
assertGet(ref2, second);
}
- EntryRef getEntryRef(const EntryVector &input) {
+ EntryRef getEntryRef(const ElemVector &input) {
for (auto itr = refStore.begin(); itr != refStore.end(); ++itr) {
if (itr->second == input) {
return itr->first;
@@ -160,12 +160,12 @@ struct ArrayStoreTest : public TestT
}
refStore = compactedRefStore;
}
- size_t entrySize() const { return sizeof(EntryT); }
+ size_t elem_size() const { return sizeof(ElemT); }
size_t largeArraySize() const { return sizeof(LargeArray); }
};
-template <typename TestT, typename EntryT, typename RefT>
-ArrayStoreTest<TestT, EntryT, RefT>::~ArrayStoreTest() = default;
+template <typename TestT, typename ElemT, typename RefT>
+ArrayStoreTest<TestT, ElemT, RefT>::~ArrayStoreTest() = default;
struct TestParam {
bool add_using_allocate;
@@ -434,22 +434,22 @@ TEST_P(NumberStoreTest, used_onHold_and_dead_memory_usage_is_tracked_for_small_a
{
MemStats exp(store.getMemoryUsage());
add({1,2,3});
- assertMemoryUsage(exp.used(entrySize() * 3));
+ assertMemoryUsage(exp.used(elem_size() * 3));
remove({1,2,3});
- assertMemoryUsage(exp.hold(entrySize() * 3));
+ assertMemoryUsage(exp.hold(elem_size() * 3));
reclaim_memory();
- assertMemoryUsage(exp.holdToDead(entrySize() * 3));
+ assertMemoryUsage(exp.holdToDead(elem_size() * 3));
}
TEST_P(NumberStoreTest, used_onHold_and_dead_memory_usage_is_tracked_for_large_arrays)
{
MemStats exp(store.getMemoryUsage());
add({1,2,3,4});
- assertMemoryUsage(exp.used(largeArraySize() + entrySize() * 4));
+ assertMemoryUsage(exp.used(largeArraySize() + elem_size() * 4));
remove({1,2,3,4});
- assertMemoryUsage(exp.hold(largeArraySize() + entrySize() * 4));
+ assertMemoryUsage(exp.hold(largeArraySize() + elem_size() * 4));
reclaim_memory();
- assertMemoryUsage(exp.decUsed(entrySize() * 4).decHold(largeArraySize() + entrySize() * 4).
+ assertMemoryUsage(exp.decUsed(elem_size() * 4).decHold(largeArraySize() + elem_size() * 4).
dead(largeArraySize()));
}
diff --git a/vespalib/src/vespa/vespalib/btree/btreestore.h b/vespalib/src/vespa/vespalib/btree/btreestore.h
index 9fdade850f1..fc991b2e295 100644
--- a/vespalib/src/vespa/vespalib/btree/btreestore.h
+++ b/vespalib/src/vespa/vespalib/btree/btreestore.h
@@ -50,8 +50,8 @@ public:
using CompactionSpec = datastore::CompactionSpec;
using CompactionStrategy = datastore::CompactionStrategy;
using EntryRef = datastore::EntryRef;
- template <typename EntryType>
- using BufferType = datastore::BufferType<EntryType>;
+ template <typename ElemT>
+ using BufferType = datastore::BufferType<ElemT>;
using BufferState = datastore::BufferState;
static constexpr uint32_t clusterLimit = 8;
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.h b/vespalib/src/vespa/vespalib/datastore/array_store.h
index c2b65d72f03..2093b7ab923 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.h
@@ -19,7 +19,7 @@
namespace vespalib::datastore {
/**
- * Datastore for storing arrays of type EntryT that is accessed via a 32-bit EntryRef.
+ * Datastore for storing arrays of type ElemT that is accessed via a 32-bit EntryRef.
*
* The default EntryRef type uses 19 bits for offset (524288 values) and 13 bits for buffer id (8192 buffers).
*
@@ -29,16 +29,18 @@ namespace vespalib::datastore {
*
* The max value of maxSmallArrayTypeId is (2^bufferBits - 1).
*/
-template <typename EntryT, typename RefT = EntryRefT<19>, typename TypeMapperT = ArrayStoreSimpleTypeMapper<EntryT> >
+template <typename ElemT, typename RefT = EntryRefT<19>, typename TypeMapperT = ArrayStoreSimpleTypeMapper<ElemT> >
class ArrayStore : public ICompactable
{
public:
using AllocSpec = ArrayStoreConfig::AllocSpec;
- using ArrayRef = vespalib::ArrayRef<EntryT>;
- using ConstArrayRef = vespalib::ConstArrayRef<EntryT>;
+ using ArrayRef = vespalib::ArrayRef<ElemT>;
+ using ConstArrayRef = vespalib::ConstArrayRef<ElemT>;
using DataStoreType = DataStoreT<RefT>;
- using LargeArray = vespalib::Array<EntryT>;
+ using ElemType = ElemT;
+ using LargeArray = vespalib::Array<ElemT>;
using LargeBufferType = typename TypeMapperT::LargeBufferType;
+ using RefType = RefT;
using SmallBufferType = typename TypeMapperT::SmallBufferType;
using TypeMapper = TypeMapperT;
private:
@@ -58,7 +60,7 @@ private:
EntryRef addLargeArray(const ConstArrayRef &array);
EntryRef allocate_large_array(size_t array_size);
ConstArrayRef getSmallArray(RefT ref, size_t arraySize) const {
- const EntryT *buf = _store.template getEntryArray<EntryT>(ref, arraySize);
+ const ElemT *buf = _store.template getEntryArray<ElemT>(ref, arraySize);
return ConstArrayRef(buf, arraySize);
}
ConstArrayRef getLargeArray(RefT ref) const {
@@ -85,7 +87,7 @@ public:
}
/**
- * Allocate an array of the given size without any instantiation of EntryT elements.
+ * Allocate an array of the given size without any instantiation of ElemT elements.
*
* Use get_writable() to get a reference to the array for writing.
*
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.hpp b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
index 301cff1e414..3ccde2e16a9 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.hpp
@@ -15,9 +15,9 @@
namespace vespalib::datastore {
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
void
-ArrayStore<EntryT, RefT, TypeMapperT>::initArrayTypes(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator)
+ArrayStore<ElemT, RefT, TypeMapperT>::initArrayTypes(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator)
{
_largeArrayTypeId = _store.addType(&_largeArrayType);
assert(_largeArrayTypeId == 0);
@@ -31,14 +31,14 @@ ArrayStore<EntryT, RefT, TypeMapperT>::initArrayTypes(const ArrayStoreConfig &cf
}
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
-ArrayStore<EntryT, RefT, TypeMapperT>::ArrayStore(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator)
+template <typename ElemT, typename RefT, typename TypeMapperT>
+ArrayStore<ElemT, RefT, TypeMapperT>::ArrayStore(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator)
: ArrayStore(cfg, memory_allocator, TypeMapper())
{
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
-ArrayStore<EntryT, RefT, TypeMapperT>::ArrayStore(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator,
+template <typename ElemT, typename RefT, typename TypeMapperT>
+ArrayStore<ElemT, RefT, TypeMapperT>::ArrayStore(const ArrayStoreConfig &cfg, std::shared_ptr<alloc::MemoryAllocator> memory_allocator,
TypeMapper&& mapper)
: _largeArrayTypeId(0),
_maxSmallArrayTypeId(cfg.maxSmallArrayTypeId()),
@@ -56,25 +56,25 @@ ArrayStore<EntryT, RefT, TypeMapperT>::ArrayStore(const ArrayStoreConfig &cfg, s
}
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
vespalib::MemoryUsage
-ArrayStore<EntryT, RefT, TypeMapperT>::getMemoryUsage() const {
+ArrayStore<ElemT, RefT, TypeMapperT>::getMemoryUsage() const {
vespalib::MemoryUsage usage = _store.getMemoryUsage();
usage.incAllocatedBytes(_smallArrayTypes.capacity() * sizeof(SmallBufferType));
usage.incUsedBytes(_smallArrayTypes.size() * sizeof(SmallBufferType));
return usage;
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
-ArrayStore<EntryT, RefT, TypeMapperT>::~ArrayStore()
+template <typename ElemT, typename RefT, typename TypeMapperT>
+ArrayStore<ElemT, RefT, TypeMapperT>::~ArrayStore()
{
_store.reclaim_all_memory();
_store.dropBuffers();
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
EntryRef
-ArrayStore<EntryT, RefT, TypeMapperT>::add(const ConstArrayRef &array)
+ArrayStore<ElemT, RefT, TypeMapperT>::add(const ConstArrayRef &array)
{
if (array.size() == 0) {
return EntryRef();
@@ -86,9 +86,9 @@ ArrayStore<EntryT, RefT, TypeMapperT>::add(const ConstArrayRef &array)
}
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
EntryRef
-ArrayStore<EntryT, RefT, TypeMapperT>::allocate(size_t array_size)
+ArrayStore<ElemT, RefT, TypeMapperT>::allocate(size_t array_size)
{
if (array_size == 0) {
return EntryRef();
@@ -100,49 +100,49 @@ ArrayStore<EntryT, RefT, TypeMapperT>::allocate(size_t array_size)
}
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
EntryRef
-ArrayStore<EntryT, RefT, TypeMapperT>::addSmallArray(const ConstArrayRef &array)
+ArrayStore<ElemT, RefT, TypeMapperT>::addSmallArray(const ConstArrayRef &array)
{
uint32_t typeId = _mapper.get_type_id(array.size());
- using NoOpReclaimer = DefaultReclaimer<EntryT>;
- return _store.template freeListAllocator<EntryT, NoOpReclaimer>(typeId).allocArray(array).ref;
+ using NoOpReclaimer = DefaultReclaimer<ElemT>;
+ return _store.template freeListAllocator<ElemT, NoOpReclaimer>(typeId).allocArray(array).ref;
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
EntryRef
-ArrayStore<EntryT, RefT, TypeMapperT>::allocate_small_array(size_t array_size)
+ArrayStore<ElemT, RefT, TypeMapperT>::allocate_small_array(size_t array_size)
{
uint32_t type_id = _mapper.get_type_id(array_size);
- return _store.template freeListRawAllocator<EntryT>(type_id).alloc(array_size).ref;
+ return _store.template freeListRawAllocator<ElemT>(type_id).alloc(array_size).ref;
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
EntryRef
-ArrayStore<EntryT, RefT, TypeMapperT>::addLargeArray(const ConstArrayRef &array)
+ArrayStore<ElemT, RefT, TypeMapperT>::addLargeArray(const ConstArrayRef &array)
{
using NoOpReclaimer = DefaultReclaimer<LargeArray>;
auto handle = _store.template freeListAllocator<LargeArray, NoOpReclaimer>(_largeArrayTypeId)
.alloc(array.cbegin(), array.cend());
auto& state = _store.getBufferState(RefT(handle.ref).bufferId());
- state.stats().inc_extra_used_bytes(sizeof(EntryT) * array.size());
+ state.stats().inc_extra_used_bytes(sizeof(ElemT) * array.size());
return handle.ref;
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
EntryRef
-ArrayStore<EntryT, RefT, TypeMapperT>::allocate_large_array(size_t array_size)
+ArrayStore<ElemT, RefT, TypeMapperT>::allocate_large_array(size_t array_size)
{
using NoOpReclaimer = DefaultReclaimer<LargeArray>;
auto handle = _store.template freeListAllocator<LargeArray, NoOpReclaimer>(_largeArrayTypeId).alloc(array_size);
auto& state = _store.getBufferState(RefT(handle.ref).bufferId());
- state.stats().inc_extra_used_bytes(sizeof(EntryT) * array_size);
+ state.stats().inc_extra_used_bytes(sizeof(ElemT) * array_size);
return handle.ref;
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
void
-ArrayStore<EntryT, RefT, TypeMapperT>::remove(EntryRef ref)
+ArrayStore<ElemT, RefT, TypeMapperT>::remove(EntryRef ref)
{
if (ref.valid()) {
RefT internalRef(ref);
@@ -151,43 +151,43 @@ ArrayStore<EntryT, RefT, TypeMapperT>::remove(EntryRef ref)
size_t arraySize = _mapper.get_array_size(typeId);
_store.holdElem(ref, arraySize);
} else {
- _store.holdElem(ref, 1, sizeof(EntryT) * get(ref).size());
+ _store.holdElem(ref, 1, sizeof(ElemT) * get(ref).size());
}
}
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
EntryRef
-ArrayStore<EntryT, RefT, TypeMapperT>::move_on_compact(EntryRef ref)
+ArrayStore<ElemT, RefT, TypeMapperT>::move_on_compact(EntryRef ref)
{
return add(get(ref));
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
ICompactionContext::UP
-ArrayStore<EntryT, RefT, TypeMapperT>::compact_worst(const CompactionStrategy &compaction_strategy)
+ArrayStore<ElemT, RefT, TypeMapperT>::compact_worst(const CompactionStrategy &compaction_strategy)
{
auto compacting_buffers = _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy);
return std::make_unique<CompactionContext>(*this, std::move(compacting_buffers));
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
std::unique_ptr<CompactingBuffers>
-ArrayStore<EntryT, RefT, TypeMapperT>::start_compact_worst_buffers(const CompactionStrategy &compaction_strategy)
+ArrayStore<ElemT, RefT, TypeMapperT>::start_compact_worst_buffers(const CompactionStrategy &compaction_strategy)
{
return _store.start_compact_worst_buffers(_compaction_spec, compaction_strategy);
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
vespalib::AddressSpace
-ArrayStore<EntryT, RefT, TypeMapperT>::addressSpaceUsage() const
+ArrayStore<ElemT, RefT, TypeMapperT>::addressSpaceUsage() const
{
return _store.getAddressSpaceUsage();
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
vespalib::MemoryUsage
-ArrayStore<EntryT, RefT, TypeMapperT>::update_stat(const CompactionStrategy& compaction_strategy)
+ArrayStore<ElemT, RefT, TypeMapperT>::update_stat(const CompactionStrategy& compaction_strategy)
{
auto address_space_usage = _store.getAddressSpaceUsage();
auto memory_usage = getMemoryUsage();
@@ -195,17 +195,17 @@ ArrayStore<EntryT, RefT, TypeMapperT>::update_stat(const CompactionStrategy& com
return memory_usage;
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
const BufferState &
-ArrayStore<EntryT, RefT, TypeMapperT>::bufferState(EntryRef ref)
+ArrayStore<ElemT, RefT, TypeMapperT>::bufferState(EntryRef ref)
{
RefT internalRef(ref);
return _store.getBufferState(internalRef.bufferId());
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
ArrayStoreConfig
-ArrayStore<EntryT, RefT, TypeMapperT>::optimizedConfigForHugePage(uint32_t maxSmallArrayTypeId,
+ArrayStore<ElemT, RefT, TypeMapperT>::optimizedConfigForHugePage(uint32_t maxSmallArrayTypeId,
size_t hugePageSize,
size_t smallPageSize,
size_t minNumArraysForNewBuffer,
@@ -220,9 +220,9 @@ ArrayStore<EntryT, RefT, TypeMapperT>::optimizedConfigForHugePage(uint32_t maxSm
allocGrowFactor);
}
-template <typename EntryT, typename RefT, typename TypeMapperT>
+template <typename ElemT, typename RefT, typename TypeMapperT>
ArrayStoreConfig
-ArrayStore<EntryT, RefT, TypeMapperT>::optimizedConfigForHugePage(uint32_t maxSmallArrayTypeId,
+ArrayStore<ElemT, RefT, TypeMapperT>::optimizedConfigForHugePage(uint32_t maxSmallArrayTypeId,
const TypeMapper& mapper,
size_t hugePageSize,
size_t smallPageSize,
@@ -233,7 +233,7 @@ ArrayStore<EntryT, RefT, TypeMapperT>::optimizedConfigForHugePage(uint32_t maxSm
[&](uint32_t type_id) noexcept { return mapper.get_array_size(type_id); },
hugePageSize,
smallPageSize,
- sizeof(EntryT),
+ sizeof(ElemT),
RefT::offsetSize(),
minNumArraysForNewBuffer,
allocGrowFactor);
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store_simple_type_mapper.h b/vespalib/src/vespa/vespalib/datastore/array_store_simple_type_mapper.h
index a0cd7827b2d..5f9728a43cc 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store_simple_type_mapper.h
+++ b/vespalib/src/vespa/vespalib/datastore/array_store_simple_type_mapper.h
@@ -15,11 +15,11 @@ namespace vespalib::datastore {
*
* A more complex mapping can be used by creating a custom mapper and BufferType implementations.
*/
-template <typename EntryT>
+template <typename ElemT>
class ArrayStoreSimpleTypeMapper {
public:
- using SmallBufferType = SmallArrayBufferType<EntryT>;
- using LargeBufferType = LargeArrayBufferType<EntryT>;
+ using SmallBufferType = SmallArrayBufferType<ElemT>;
+ using LargeBufferType = LargeArrayBufferType<ElemT>;
uint32_t get_type_id(size_t array_size) const { return array_size; }
size_t get_array_size(uint32_t type_id) const { return type_id; }
diff --git a/vespalib/src/vespa/vespalib/datastore/buffer_type.h b/vespalib/src/vespa/vespalib/datastore/buffer_type.h
index bedbb2c984e..625ad147d36 100644
--- a/vespalib/src/vespa/vespalib/datastore/buffer_type.h
+++ b/vespalib/src/vespa/vespalib/datastore/buffer_type.h
@@ -126,13 +126,16 @@ protected:
};
/**
- * Concrete class used to manage allocation and de-allocation of elements of type EntryType in data store buffers.
+ * Concrete class used to manage allocation and de-allocation of elements of type ElemType in data store buffers.
*/
-template <typename EntryType, typename EmptyType = EntryType>
+template <typename ElemT, typename EmptyT = ElemT>
class BufferType : public BufferTypeBase
{
+public:
+ using ElemType = ElemT;
+ using EmptyType = EmptyT;
protected:
- static const EntryType& empty_entry() noexcept;
+ static const ElemType& empty_entry() noexcept;
public:
BufferType() noexcept : BufferType(1,1,1) {}
@@ -148,7 +151,7 @@ public:
void fallbackCopy(void *newBuffer, const void *oldBuffer, ElemCount numElems) override;
void initializeReservedElements(void *buffer, ElemCount reservedElements) override;
void cleanHold(void *buffer, size_t offset, ElemCount numElems, CleanContext cleanCxt) override;
- size_t elementSize() const override { return sizeof(EntryType); }
+ size_t elementSize() const override { return sizeof(ElemType); }
};
extern template class BufferType<char>;
diff --git a/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp b/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp
index 72c8f574a70..504194e1791 100644
--- a/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/buffer_type.hpp
@@ -6,63 +6,61 @@
namespace vespalib::datastore {
-template <typename EntryType, typename EmptyType>
-BufferType<EntryType, EmptyType>::BufferType(uint32_t arraySize, uint32_t minArrays, uint32_t maxArrays) noexcept
+template <typename ElemT, typename EmptyT>
+BufferType<ElemT, EmptyT>::BufferType(uint32_t arraySize, uint32_t minArrays, uint32_t maxArrays) noexcept
: BufferTypeBase(arraySize, minArrays, maxArrays)
{ }
-template <typename EntryType, typename EmptyType>
-BufferType<EntryType, EmptyType>::BufferType(uint32_t arraySize, uint32_t minArrays, uint32_t maxArrays,
+template <typename ElemT, typename EmptyT>
+BufferType<ElemT, EmptyT>::BufferType(uint32_t arraySize, uint32_t minArrays, uint32_t maxArrays,
uint32_t numArraysForNewBuffer, float allocGrowFactor) noexcept
: BufferTypeBase(arraySize, minArrays, maxArrays, numArraysForNewBuffer, allocGrowFactor)
{ }
-template <typename EntryType, typename EmptyType>
-BufferType<EntryType, EmptyType>::~BufferType() = default;
+template <typename ElemT, typename EmptyT>
+BufferType<ElemT, EmptyT>::~BufferType() = default;
-template <typename EntryType, typename EmptyType>
+template <typename ElemT, typename EmptyT>
void
-BufferType<EntryType, EmptyType>::destroyElements(void *buffer, ElemCount numElems)
+BufferType<ElemT, EmptyT>::destroyElements(void *buffer, ElemCount numElems)
{
- EntryType *e = static_cast<EntryType *>(buffer);
+ ElemType *e = static_cast<ElemType *>(buffer);
for (size_t j = numElems; j != 0; --j) {
- e->~EntryType();
+ e->~ElemType();
++e;
}
}
-template <typename EntryType, typename EmptyType>
+template <typename ElemT, typename EmptyT>
void
-BufferType<EntryType, EmptyType>::fallbackCopy(void *newBuffer,
- const void *oldBuffer,
- ElemCount numElems)
+BufferType<ElemT, EmptyT>::fallbackCopy(void *newBuffer, const void *oldBuffer, ElemCount numElems)
{
- EntryType *d = static_cast<EntryType *>(newBuffer);
- const EntryType *s = static_cast<const EntryType *>(oldBuffer);
+ ElemType *d = static_cast<ElemType *>(newBuffer);
+ const ElemType *s = static_cast<const ElemType *>(oldBuffer);
for (size_t j = numElems; j != 0; --j) {
- new (static_cast<void *>(d)) EntryType(*s);
+ new (static_cast<void *>(d)) ElemType(*s);
++s;
++d;
}
}
-template <typename EntryType, typename EmptyType>
+template <typename ElemT, typename EmptyT>
void
-BufferType<EntryType, EmptyType>::initializeReservedElements(void *buffer, ElemCount reservedElems)
+BufferType<ElemT, EmptyT>::initializeReservedElements(void *buffer, ElemCount reservedElems)
{
- EntryType *e = static_cast<EntryType *>(buffer);
+ ElemType *e = static_cast<ElemType *>(buffer);
const auto& empty = empty_entry();
for (size_t j = reservedElems; j != 0; --j) {
- new (static_cast<void *>(e)) EntryType(empty);
+ new (static_cast<void *>(e)) ElemType(empty);
++e;
}
}
-template <typename EntryType, typename EmptyType>
+template <typename ElemT, typename EmptyT>
void
-BufferType<EntryType, EmptyType>::cleanHold(void *buffer, size_t offset, ElemCount numElems, CleanContext)
+BufferType<ElemT, EmptyT>::cleanHold(void *buffer, size_t offset, ElemCount numElems, CleanContext)
{
- EntryType *e = static_cast<EntryType *>(buffer) + offset;
+ ElemType *e = static_cast<ElemType *>(buffer) + offset;
const auto& empty = empty_entry();
for (size_t j = numElems; j != 0; --j) {
*e = empty;
@@ -70,14 +68,14 @@ BufferType<EntryType, EmptyType>::cleanHold(void *buffer, size_t offset, ElemCou
}
}
-template <typename EntryType, typename EmptyType>
-const EntryType&
-BufferType<EntryType, EmptyType>::empty_entry() noexcept
+template <typename ElemT, typename EmptyT>
+const ElemT&
+BufferType<ElemT, EmptyT>::empty_entry() noexcept
{
- // It's possible for EntryType to wrap e.g. an Alloc instance, which has a transitive
+ // It's possible for ElemType to wrap e.g. an Alloc instance, which has a transitive
// dependency on globally constructed allocator object(s). To avoid issues with global
// construction order, initialize the sentinel on the first access.
- static EntryType empty = EmptyType();
+ static ElemType empty = EmptyType();
return empty;
}
diff --git a/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.h b/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.h
index 600925969a3..6fd5d694fb1 100644
--- a/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.h
+++ b/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.h
@@ -14,11 +14,11 @@ namespace vespalib::datastore {
/*
* Class representing buffer type for large arrays in ArrayStore
*/
-template <typename EntryT>
-class LargeArrayBufferType : public BufferType<Array<EntryT>>
+template <typename ElemT>
+class LargeArrayBufferType : public BufferType<Array<ElemT>>
{
using AllocSpec = ArrayStoreConfig::AllocSpec;
- using ArrayType = Array<EntryT>;
+ using ArrayType = Array<ElemT>;
using ParentType = BufferType<ArrayType>;
using ParentType::empty_entry;
using CleanContext = typename ParentType::CleanContext;
diff --git a/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.hpp b/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.hpp
index 3042bbff73f..102c13ef1cc 100644
--- a/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.hpp
@@ -7,32 +7,32 @@
namespace vespalib::datastore {
-template <typename EntryT>
-LargeArrayBufferType<EntryT>::LargeArrayBufferType(const AllocSpec& spec, std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept
- : BufferType<Array<EntryT>>(1u, spec.minArraysInBuffer, spec.maxArraysInBuffer, spec.numArraysForNewBuffer, spec.allocGrowFactor),
+template <typename ElemT>
+LargeArrayBufferType<ElemT>::LargeArrayBufferType(const AllocSpec& spec, std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept
+ : BufferType<Array<ElemT>>(1u, spec.minArraysInBuffer, spec.maxArraysInBuffer, spec.numArraysForNewBuffer, spec.allocGrowFactor),
_memory_allocator(std::move(memory_allocator))
{
}
-template <typename EntryT>
-LargeArrayBufferType<EntryT>::~LargeArrayBufferType() = default;
+template <typename ElemT>
+LargeArrayBufferType<ElemT>::~LargeArrayBufferType() = default;
-template <typename EntryT>
+template <typename ElemT>
void
-LargeArrayBufferType<EntryT>::cleanHold(void* buffer, size_t offset, ElemCount numElems, CleanContext cleanCtx)
+LargeArrayBufferType<ElemT>::cleanHold(void* buffer, size_t offset, ElemCount numElems, CleanContext cleanCtx)
{
ArrayType* elem = static_cast<ArrayType*>(buffer) + offset;
const auto& empty = empty_entry();
for (size_t i = 0; i < numElems; ++i) {
- cleanCtx.extraBytesCleaned(sizeof(EntryT) * elem->size());
+ cleanCtx.extraBytesCleaned(sizeof(ElemT) * elem->size());
*elem = empty;
++elem;
}
}
-template <typename EntryT>
+template <typename ElemT>
const vespalib::alloc::MemoryAllocator*
-LargeArrayBufferType<EntryT>::get_memory_allocator() const
+LargeArrayBufferType<ElemT>::get_memory_allocator() const
{
return _memory_allocator.get();
}
diff --git a/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.h b/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.h
index 676a9d3790f..6bb6601839d 100644
--- a/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.h
+++ b/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.h
@@ -13,8 +13,8 @@ namespace vespalib::datastore {
/*
* Class representing buffer type for small arrays in ArrayStore
*/
-template <typename EntryT>
-class SmallArrayBufferType : public BufferType<EntryT>
+template <typename ElemT>
+class SmallArrayBufferType : public BufferType<ElemT>
{
using AllocSpec = ArrayStoreConfig::AllocSpec;
std::shared_ptr<alloc::MemoryAllocator> _memory_allocator;
diff --git a/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.hpp b/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.hpp
index 414804417eb..b38d8f84275 100644
--- a/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/small_array_buffer_type.hpp
@@ -6,19 +6,19 @@
namespace vespalib::datastore {
-template <typename EntryT>
-SmallArrayBufferType<EntryT>::SmallArrayBufferType(uint32_t array_size, const AllocSpec& spec, std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept
- : BufferType<EntryT>(array_size, spec.minArraysInBuffer, spec.maxArraysInBuffer, spec.numArraysForNewBuffer, spec.allocGrowFactor),
+template <typename ElemT>
+SmallArrayBufferType<ElemT>::SmallArrayBufferType(uint32_t array_size, const AllocSpec& spec, std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept
+ : BufferType<ElemT>(array_size, spec.minArraysInBuffer, spec.maxArraysInBuffer, spec.numArraysForNewBuffer, spec.allocGrowFactor),
_memory_allocator(std::move(memory_allocator))
{
}
-template <typename EntryT>
-SmallArrayBufferType<EntryT>::~SmallArrayBufferType() = default;
+template <typename ElemT>
+SmallArrayBufferType<ElemT>::~SmallArrayBufferType() = default;
-template <typename EntryT>
+template <typename ElemT>
const vespalib::alloc::MemoryAllocator*
-SmallArrayBufferType<EntryT>::get_memory_allocator() const
+SmallArrayBufferType<ElemT>::get_memory_allocator() const
{
return _memory_allocator.get();
}