// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "array_store_type_mapper.h" #include "atomic_entry_ref.h" namespace vespalib::datastore { template class SmallArrayBufferType; template class DynamicArrayBufferType; template class LargeArrayBufferType; /* * This class provides mapping between type ids and array sizes needed for * storing values. * * Type ids [1;max_static_array_buffer_type_id] use SmallBufferType, * containing small arrays where buffer type specifies array size. * * Type ids [max_static_array_buffer_type_id+1;max_buffer_type_id] use * DynamicBufferType, containing medium sized arrays where the same * buffer type handles a range of array sizes and actual array size is * also stored in the entry. * * Type id 0 uses LargeBufferType, which handles any array size but uses * heap allocation. */ template class ArrayStoreDynamicTypeMapper : public vespalib::datastore::ArrayStoreTypeMapper { uint32_t _max_static_array_buffer_type_id; public: using SmallBufferType = vespalib::datastore::SmallArrayBufferType; using DynamicBufferType = vespalib::datastore::DynamicArrayBufferType; using LargeBufferType = vespalib::datastore::LargeArrayBufferType; ArrayStoreDynamicTypeMapper(); ArrayStoreDynamicTypeMapper(uint32_t max_buffer_type_id, double grow_factor, size_t max_buffer_size); ~ArrayStoreDynamicTypeMapper(); void setup_array_sizes(uint32_t max_buffer_type_id, double grow_factor, size_t max_buffer_size); size_t get_entry_size(uint32_t type_id) const; bool is_dynamic_buffer(uint32_t type_id) const noexcept { return type_id > _max_static_array_buffer_type_id; } uint32_t count_dynamic_buffer_types(uint32_t max_type_id) const noexcept { return (max_type_id > _max_static_array_buffer_type_id) ? (max_type_id - _max_static_array_buffer_type_id) : 0u; } }; extern template class ArrayStoreDynamicTypeMapper; extern template class ArrayStoreDynamicTypeMapper; extern template class ArrayStoreDynamicTypeMapper; extern template class ArrayStoreDynamicTypeMapper; extern template class ArrayStoreDynamicTypeMapper; extern template class ArrayStoreDynamicTypeMapper; extern template class ArrayStoreDynamicTypeMapper; extern template class ArrayStoreDynamicTypeMapper; }