diff --git a/include/cista/containers/paged.h b/include/cista/containers/paged.h index 793bc52e..a8f16f12 100644 --- a/include/cista/containers/paged.h +++ b/include/cista/containers/paged.h @@ -11,22 +11,23 @@ namespace cista { -template +template struct page { bool valid() const { return capacity_ != 0U; } - SizeType size() const noexcept { return size_; } + PageSizeType size() const noexcept { return size_; } - SizeType size_{0U}; - SizeType capacity_{0U}; + PageSizeType size_{0U}; + PageSizeType capacity_{0U}; SizeType start_{0U}; }; template ) / + next_power_of_two(sizeof(page) / sizeof(typename DataVec::value_type))), - SizeType MaxPageSize = 65536U> + PageSizeType MaxPageSize = 4096> struct paged { using value_type = typename DataVec::value_type; using iterator = typename DataVec::iterator; @@ -34,19 +35,21 @@ struct paged { using reference = typename DataVec::reference; using const_reference = typename DataVec::const_reference; using size_type = SizeType; - using page_t = page; + using page_size_type = PageSizeType; + using page_t = page; static_assert(sizeof(value_type) * MinPageSize >= sizeof(page_t)); static_assert(std::is_trivially_copyable_v); - static constexpr size_type free_list_index(size_type const capacity) { + static constexpr std::size_t free_list_index(size_type const capacity) { return static_cast(constexpr_trailing_zeros(capacity) - constexpr_trailing_zeros(MinPageSize)); } - static constexpr size_type free_list_size = free_list_index(MaxPageSize) + 1U; + static constexpr auto const free_list_size = + free_list_index(MaxPageSize) + 1U; - page_t resize_page(page_t const& p, size_type const size) { + page_t resize_page(page_t const& p, PageSizeType const size) { if (size <= p.capacity_) { return {size, p.capacity_, p.start_}; } else { @@ -57,12 +60,12 @@ struct paged { } } - page_t create_page(size_type const size) { + page_t create_page(PageSizeType const size) { auto const capacity = next_power_of_two(std::max(MinPageSize, size)); auto const i = free_list_index(capacity); verify(i < free_list_.size(), "paged::create_page: size > max capacity"); if (!free_list_[i].empty()) { - auto start = free_list_[i].pop(*this); + auto const start = free_list_[i].pop(*this); return {size, capacity, start}; } else { auto const start = data_.size(); diff --git a/include/cista/containers/paged_vecvec.h b/include/cista/containers/paged_vecvec.h index e8aadc66..45cdb3c6 100644 --- a/include/cista/containers/paged_vecvec.h +++ b/include/cista/containers/paged_vecvec.h @@ -271,7 +271,8 @@ struct paged_vecvec { typename = std::enable_if_t().begin()), data_value_type>>> void emplace_back(Container&& bucket) { - auto p = paged_.create_page(static_cast(bucket.size())); + auto p = paged_.create_page( + static_cast(bucket.size())); paged_.copy(p, std::begin(bucket), std::end(bucket)); idx_.emplace_back(p); } diff --git a/test/vecvec_test.cc b/test/vecvec_test.cc index f8568221..7c3ac0b3 100644 --- a/test/vecvec_test.cc +++ b/test/vecvec_test.cc @@ -160,7 +160,7 @@ TEST_CASE("paged_vecvec mmap") { using key = cista::strong; using data_t = cista::paged>; - using idx_t = cista::mmap_vec>; + using idx_t = cista::mmap_vec; auto idx = idx_t{cista::mmap{std::tmpnam(nullptr)}}; auto data = data_t{cista::mmap_vec{cista::mmap{std::tmpnam(nullptr)}}}; @@ -194,14 +194,14 @@ TEST_CASE("paged_vecvec mmap") { TEST_CASE("paged_vecvec vector") { using key = cista::strong; using data_t = cista::paged>; - using idx_t = cista::mmap_vec>; + using idx_t = cista::mmap_vec; auto idx = idx_t{cista::mmap{std::tmpnam(nullptr)}}; auto data = data_t{}; auto d = cista::paged_vecvec{std::move(data), std::move(idx)}; - d.resize(3); + d.resize(3U); CHECK_EQ(3, d.size()); d.emplace_back("hello");