From 6a16477ab3d7d00a1faf711dc58a61f7bdafb048 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 16:39:44 -0400 Subject: [PATCH 01/10] Remove dead code. --- .../database/impl/memory/mmap_dispatch.ipp | 26 ++--------- .../database/impl/primitives/manager.ipp | 12 ++++- include/bitcoin/database/memory/accessor.hpp | 11 +++++ .../database/memory/interfaces/storage.hpp | 5 --- include/bitcoin/database/memory/mmap.hpp | 4 -- test/memory/mmap.cpp | 45 ++++++++++--------- test/mocks/chunk_storage.hpp | 12 +---- 7 files changed, 48 insertions(+), 67 deletions(-) diff --git a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp index f2ca4b458..09a0a30d5 100644 --- a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp +++ b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp @@ -103,29 +103,9 @@ memory::iterator CLASS::get_at_raw(size_t column, size_t offset) const NOEXCEPT TEMPLATE memory_ptr CLASS::get(size_t offset) const NOEXCEPT { - return get_at(zero, offset); -} - -TEMPLATE -memory_ptr CLASS::get_at(size_t column, size_t offset) const NOEXCEPT -{ - if (column >= columns) - return {}; - - // Obtaining size before access prevents mutual mutex wait (deadlock). - const auto allocated = size() * widths.at(column); - - // Takes a shared lock on remap_mutex_ until destruct, blocking remap. - const auto ptr = std::make_shared(remap_mutex_); - - // loaded_ update is precluded by above lock, making this read atomic. - if (!loaded_ || is_null(ptr)) - return {}; - - // With offset > size the assignment is negative (stream is exhausted). - auto data = memory_map_.at(column); - ptr->assign(std::next(data, offset), std::next(data, allocated)); - return ptr; + auto out = get_at1(zero, offset); + if (!out) return {}; + return std::make_shared(std::move(out)); } TEMPLATE diff --git a/include/bitcoin/database/impl/primitives/manager.ipp b/include/bitcoin/database/impl/primitives/manager.ipp index a1a0b0cba..913676ddb 100644 --- a/include/bitcoin/database/impl/primitives/manager.ipp +++ b/include/bitcoin/database/impl/primitives/manager.ipp @@ -31,7 +31,11 @@ inline memory_ptr CLASS::get() const NOEXCEPT if constexpr (is_one(columns)) return files_.get(); else - return files_.get_at(Column); + { + auto out = files_.get_at1(Column); + if (!out) return {}; + return std::make_shared(std::move(out)); + } } TEMPLATE @@ -57,7 +61,11 @@ inline memory_ptr CLASS::get(const Link& link) const NOEXCEPT if constexpr (is_one(columns)) return files_.get(position); else - return files_.get_at(Column, position); + { + auto out = files_.get_at1(Column, position); + if (!out) return {}; + return std::make_shared(std::move(out)); + } } TEMPLATE diff --git a/include/bitcoin/database/memory/accessor.hpp b/include/bitcoin/database/memory/accessor.hpp index c4a1cb541..490489190 100644 --- a/include/bitcoin/database/memory/accessor.hpp +++ b/include/bitcoin/database/memory/accessor.hpp @@ -61,6 +61,17 @@ class accessor final ////BC_ASSERT(!system::is_negative(size())); } + /// Release lock and invalidate pointers (idempotent). + inline void reset() NOEXCEPT + { + if (!is_null(begin_)) + { + shared_lock_.unlock(); + begin_ = nullptr; + end_ = nullptr; + } + } + /// memory interface /// ----------------------------------------------------------------------- diff --git a/include/bitcoin/database/memory/interfaces/storage.hpp b/include/bitcoin/database/memory/interfaces/storage.hpp index 7c7343dad..bd686645f 100644 --- a/include/bitcoin/database/memory/interfaces/storage.hpp +++ b/include/bitcoin/database/memory/interfaces/storage.hpp @@ -109,11 +109,6 @@ class storage /// Pointer is constrained to starting write within logical allocation. virtual memory_ptr get(size_t offset=zero) const NOEXCEPT = 0; - /// Same as get() but within specified column (or null for invalid column). - /// Pointer is constrained to starting write within logical allocation. - virtual memory_ptr get_at(size_t column, - size_t offset=zero) const NOEXCEPT = 0; - /// Get remap-protected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within logical allocation. virtual memory get1(size_t offset=zero) const NOEXCEPT = 0; diff --git a/include/bitcoin/database/memory/mmap.hpp b/include/bitcoin/database/memory/mmap.hpp index b78d6ec33..6271aad67 100644 --- a/include/bitcoin/database/memory/mmap.hpp +++ b/include/bitcoin/database/memory/mmap.hpp @@ -148,10 +148,6 @@ class mmap /// Remap-protected r/w access to start/offset (or null), within logical. memory_ptr get(size_t offset=zero) const NOEXCEPT override; - /// Same as get() but within specified column (or null for invalid column). - memory_ptr get_at(size_t column, - size_t offset=zero) const NOEXCEPT override; - /// Remap-protected r/w access to start/offset (or null), within logical. memory get1(size_t offset=zero) const NOEXCEPT override; diff --git a/test/memory/mmap.cpp b/test/memory/mmap.cpp index 480cd38ef..87ed9221e 100644 --- a/test/memory/mmap.cpp +++ b/test/memory/mmap.cpp @@ -164,6 +164,7 @@ BOOST_AUTO_TEST_CASE(mmap__load__unloaded__true) BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } + BOOST_AUTO_TEST_CASE(mmap__load__shared__load_locked) { const std::string file = TEST_PATH; @@ -824,15 +825,15 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) // Row zero, written before remap (verifies preservation across remap). BOOST_REQUIRE_EQUAL(instance.allocate(1), zero); - auto write0_column0 = instance.get_at(0, 0); - auto write0_column1 = instance.get_at(1, 0); + auto write0_column0 = instance.get_at1(0, 0); + auto write0_column1 = instance.get_at1(1, 0); BOOST_REQUIRE(write0_column0); BOOST_REQUIRE(write0_column1); - write0_column0->begin()[0] = 'a'; - write0_column1->begin()[0] = 'b'; - write0_column1->begin()[1] = 'c'; - write0_column1->begin()[2] = 'd'; + write0_column0.begin()[0] = 'a'; + write0_column1.begin()[0] = 'b'; + write0_column1.begin()[1] = 'c'; + write0_column1.begin()[2] = 'd'; write0_column0.reset(); write0_column1.reset(); @@ -847,15 +848,15 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) BOOST_REQUIRE_EQUAL(std::filesystem::file_size(files.back()), rows * 3u); // Last row, through the remapped pointers. - auto write1_column0 = instance.get_at(0, last * 1); - auto write1_column1 = instance.get_at(1, last * 3); + auto write1_column0 = instance.get_at1(0, last * 1); + auto write1_column1 = instance.get_at1(1, last * 3); BOOST_REQUIRE(write1_column0); BOOST_REQUIRE(write1_column1); - write1_column0->begin()[0] = 'w'; - write1_column1->begin()[0] = 'x'; - write1_column1->begin()[1] = 'y'; - write1_column1->begin()[2] = 'z'; + write1_column0.begin()[0] = 'w'; + write1_column1.begin()[0] = 'x'; + write1_column1.begin()[1] = 'y'; + write1_column1.begin()[2] = 'z'; write1_column0.reset(); write1_column1.reset(); BOOST_REQUIRE(!instance.unload()); @@ -868,18 +869,18 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) BOOST_REQUIRE(!instance.load()); BOOST_REQUIRE_EQUAL(instance.size(), rows); - auto read_column0 = instance.get_at(0, 0); - auto read_column1 = instance.get_at(1, 0); + auto read_column0 = instance.get_at1(0, 0); + auto read_column1 = instance.get_at1(1, 0); BOOST_REQUIRE(read_column0); BOOST_REQUIRE(read_column1); - BOOST_REQUIRE_EQUAL(read_column0->begin()[0], 'a'); - BOOST_REQUIRE_EQUAL(read_column0->begin()[last], 'w'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[0], 'b'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[1], 'c'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[2], 'd'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[last * 3 + 0], 'x'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[last * 3 + 1], 'y'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[last * 3 + 2], 'z'); + BOOST_REQUIRE_EQUAL(read_column0.begin()[0], 'a'); + BOOST_REQUIRE_EQUAL(read_column0.begin()[last], 'w'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[0], 'b'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[1], 'c'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[2], 'd'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[last * 3 + 0], 'x'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[last * 3 + 1], 'y'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[last * 3 + 2], 'z'); read_column0.reset(); read_column1.reset(); diff --git a/test/mocks/chunk_storage.hpp b/test/mocks/chunk_storage.hpp index 55a97ce59..19b38ece3 100644 --- a/test/mocks/chunk_storage.hpp +++ b/test/mocks/chunk_storage.hpp @@ -283,17 +283,7 @@ class chunk_storages memory_ptr get(size_t offset=zero) const NOEXCEPT override { - return get_at(zero, offset); - } - - memory_ptr get_at(size_t column, size_t offset=zero) const NOEXCEPT override - { - using namespace system; - auto data = at(column).data(); - const auto allocated = size() * widths.at(column); - const auto ptr = emplace_shared(map_mutex_); - ptr->assign(std::next(data, offset), std::next(data, allocated)); - return ptr; + return std::make_shared(get1(offset)); } memory get1(size_t offset=zero) const NOEXCEPT override From 289a3e4a744f49848e0ed3abd43fd79f254481f8 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 16:48:34 -0400 Subject: [PATCH 02/10] Style, comments. --- include/bitcoin/database/memory/accessor.hpp | 45 +++++++++----------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/include/bitcoin/database/memory/accessor.hpp b/include/bitcoin/database/memory/accessor.hpp index 490489190..8dfda4a4f 100644 --- a/include/bitcoin/database/memory/accessor.hpp +++ b/include/bitcoin/database/memory/accessor.hpp @@ -25,8 +25,8 @@ namespace libbitcoin { namespace database { +/// Not thread safe. /// Shared r/w access to a memory buffer, mutex blocks memory remap. -/// Zero/negative size is allowed (automatically handled by bc streams). class accessor final { public: @@ -50,7 +50,14 @@ class accessor final { } + /// True if holds lock on memory buffer. + inline operator bool() const NOEXCEPT + { + return !is_null(begin_); + } + /// Set the buffer, where end is within allocated space. + /// Zero/negative size is allowed (automatically handled by bc streams). /// End should be initialized to logical space though that may contract or /// expand during accessor lifetime. The only guarantee offered by end is /// that it remains within allocated space and is initially logical space. @@ -58,7 +65,6 @@ class accessor final { begin_ = begin; end_ = end; - ////BC_ASSERT(!system::is_negative(size())); } /// Release lock and invalidate pointers (idempotent). @@ -72,33 +78,19 @@ class accessor final } } - /// memory interface - /// ----------------------------------------------------------------------- - - inline operator bool() const NOEXCEPT - { - return !is_null(begin_); - } - - /// Return an offset from begin, nullptr if end or past end. + /// Return an offset from begin, nullptr if past buffer. inline uint8_t* offset(size_t bytes) const NOEXCEPT { if (system::is_greater(bytes, size())) return nullptr; - BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) - return begin_ + bytes; - BC_POP_WARNING() - ////return std::next(begin_, bytes); + return std::next(begin_, bytes); } /// The logical buffer size (from begin to end). inline ptrdiff_t size() const NOEXCEPT { - BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) - return system::possible_narrow_and_sign_cast(end_ - begin_); - BC_POP_WARNING() - ////return std::distance(begin_, end_); + return std::distance(begin_, end_); } /// Alias for begin. @@ -107,12 +99,6 @@ class accessor final return begin(); } - /// Get logical buffer (guarded against remap only). - inline operator system::data_slab() const NOEXCEPT - { - return { begin(), end() }; - }; - /// Buffer start. inline uint8_t* begin() const NOEXCEPT { @@ -125,9 +111,18 @@ class accessor final return end_; } + /// Get logical buffer (guarded against remap only). + inline operator system::data_slab() const NOEXCEPT + { + return { begin(), end() }; + }; + private: + // These are not thread safe. uint8_t* begin_{}; uint8_t* end_{}; + + // This is thread safe. std::shared_lock shared_lock_; }; From 61d3ffe440b050b3c6e547e99396f95a94e645b6 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 17:02:57 -0400 Subject: [PATCH 03/10] Rename mmap::set(...) to get_filled(...). --- .../database/impl/memory/mmap_dispatch.ipp | 3 +- .../database/impl/primitives/arrayhead.ipp | 3 +- .../database/memory/interfaces/storage.hpp | 2 +- include/bitcoin/database/memory/mmap.hpp | 2 +- test/memory/mmap.cpp | 30 +++++++++---------- test/mocks/chunk_storage.hpp | 3 +- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp index 09a0a30d5..2e8df858a 100644 --- a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp +++ b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp @@ -34,7 +34,8 @@ namespace database { // ---------------------------------------------------------------------------- TEMPLATE -memory_ptr CLASS::set(size_t offset, size_t size, uint8_t backfill) NOEXCEPT +memory_ptr CLASS::get_filled(size_t offset, size_t size, + uint8_t backfill) NOEXCEPT { // This is basically allocate(...) for application to a table head. { diff --git a/include/bitcoin/database/impl/primitives/arrayhead.ipp b/include/bitcoin/database/impl/primitives/arrayhead.ipp index b80df826d..dc2a673f7 100644 --- a/include/bitcoin/database/impl/primitives/arrayhead.ipp +++ b/include/bitcoin/database/impl/primitives/arrayhead.ipp @@ -167,7 +167,8 @@ bool CLASS::push(const Link& link, const Link& index) NOEXCEPT constexpr auto fill = bit_all; // Allocate as necessary and fill allocations. - const auto ptr = file_.set(link_to_position(index), bucket_size, fill); + const auto position = link_to_position(index); + const auto ptr = file_.get_filled(position, bucket_size, fill); if (is_null(ptr)) return false; diff --git a/include/bitcoin/database/memory/interfaces/storage.hpp b/include/bitcoin/database/memory/interfaces/storage.hpp index bd686645f..169e2e30b 100644 --- a/include/bitcoin/database/memory/interfaces/storage.hpp +++ b/include/bitcoin/database/memory/interfaces/storage.hpp @@ -89,7 +89,7 @@ class storage virtual size_t allocate(size_t count) NOEXCEPT = 0; /// Get remap-protected r/w access to offset (or null) allocated to size. - virtual memory_ptr set(size_t offset, size_t size, + virtual memory_ptr get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT = 0; /// Get remap-protected r/w access to start/offset of memory map (or null). diff --git a/include/bitcoin/database/memory/mmap.hpp b/include/bitcoin/database/memory/mmap.hpp index 6271aad67..51f203bcd 100644 --- a/include/bitcoin/database/memory/mmap.hpp +++ b/include/bitcoin/database/memory/mmap.hpp @@ -132,7 +132,7 @@ class mmap size_t allocate(size_t count) NOEXCEPT override; /// Remap-protected r/w access to offset (or null) allocated to size. - memory_ptr set(size_t offset, size_t size, + memory_ptr get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT override; /// Remap-protected r/w access to start/offset (or null), within capacity. diff --git a/test/memory/mmap.cpp b/test/memory/mmap.cpp index 87ed9221e..abf93ea8d 100644 --- a/test/memory/mmap.cpp +++ b/test/memory/mmap.cpp @@ -441,18 +441,18 @@ BOOST_AUTO_TEST_CASE(mmap__truncate__decrease__success_logical_decreased_capacit BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__unloaded__false) +BOOST_AUTO_TEST_CASE(mmap__get_filled__unloaded__false) { const std::string file = TEST_PATH; BOOST_REQUIRE(test::create(file)); map instance(file); BOOST_REQUIRE(!instance.open()); - BOOST_REQUIRE(!instance.set(42, 24, 0xff)); + BOOST_REQUIRE(!instance.get_filled(42, 24, 0xff)); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_capacity) +BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_capacity) { constexpr auto half_rate = 50_size; constexpr auto minimum = 42_size; @@ -467,7 +467,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_capacity) BOOST_REQUIRE(!instance.load()); BOOST_REQUIRE_EQUAL(instance.capacity(), minimum); - auto memory = instance.set(offset, size, fill); + auto memory = instance.get_filled(offset, size, fill); BOOST_REQUIRE(memory); const auto expected = std::next(instance.get()->data(), offset); @@ -483,7 +483,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_capacity) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__add_overflow__eof) +BOOST_AUTO_TEST_CASE(mmap__get_filled__add_overflow__eof) { const std::string file = TEST_PATH; BOOST_REQUIRE(test::create(file)); @@ -491,14 +491,14 @@ BOOST_AUTO_TEST_CASE(mmap__set__add_overflow__eof) map instance(file); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.set(100, 24, 0xff)); - BOOST_REQUIRE(!instance.set(max_size_t, 24, 0xff)); + BOOST_REQUIRE(instance.get_filled(100, 24, 0xff)); + BOOST_REQUIRE(!instance.get_filled(max_size_t, 24, 0xff)); BOOST_REQUIRE(!instance.unload()); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__minimum_no_expansion__expected_capacity) +BOOST_AUTO_TEST_CASE(mmap__get_filled__minimum_no_expansion__expected_capacity) { constexpr auto rate = 0_size; constexpr auto minimum = 42_size; @@ -511,7 +511,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__minimum_no_expansion__expected_capacity) map instance(file, minimum, rate); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.set(offset, size, fill)); + BOOST_REQUIRE(instance.get_filled(offset, size, fill)); constexpr auto capacity = std::max(minimum, offset + size); BOOST_REQUIRE_EQUAL(instance.capacity(), capacity); @@ -520,7 +520,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__minimum_no_expansion__expected_capacity) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__no_minimum_expansion__expected_capacity) +BOOST_AUTO_TEST_CASE(mmap__get_filled__no_minimum_expansion__expected_capacity) { // map will fail if minimum is zero. constexpr auto rate = 42_size; @@ -534,7 +534,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__no_minimum_expansion__expected_capacity) map instance(file, minimum, rate); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.set(offset, size, fill)); + BOOST_REQUIRE(instance.get_filled(offset, size, fill)); // These add only because offset + size is 100. constexpr auto capacity = offset + size + rate; @@ -544,7 +544,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__no_minimum_expansion__expected_capacity) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) +BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_fill) { BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) @@ -560,7 +560,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.set(offset1, size1, fill1); + auto memory = instance.get_filled(offset1, size1, fill1); BOOST_REQUIRE(memory); constexpr auto capacity = offset1 + size1 + to_half(offset1 + size1); @@ -590,7 +590,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) constexpr auto offset2 = 15_size; constexpr auto fill2 = 0b1111'0000; memory.reset(); - memory = instance.set(offset2, size2, fill2); + memory = instance.get_filled(offset2, size2, fill2); BOOST_REQUIRE(memory); constexpr auto capacity2 = offset2 + size2 + to_half(offset2 + size2); @@ -603,7 +603,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) data[18] = 'g'; data[19] = 'h'; - // Get data again in case it has been remapped by set(). + // Get data again in case it has been remapped by get_filled(). data = instance.get()->data(); ////BOOST_REQUIRE_EQUAL(data[ 0], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 1], 0x00_u8); // cannot assume mmap default fill diff --git a/test/mocks/chunk_storage.hpp b/test/mocks/chunk_storage.hpp index 19b38ece3..cf0433766 100644 --- a/test/mocks/chunk_storage.hpp +++ b/test/mocks/chunk_storage.hpp @@ -240,7 +240,8 @@ class chunk_storages // access // ------------------------------------------------------------------------ - memory_ptr set(size_t offset, size_t size, uint8_t backfill) NOEXCEPT override + memory_ptr get_filled(size_t offset, size_t size, + uint8_t backfill) NOEXCEPT override { { std::unique_lock field_lock(field_mutex_); From 8661a5e2914633715e7018b589031615cf043a4d Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 17:26:15 -0400 Subject: [PATCH 04/10] Style. --- test/memory/mmap.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/memory/mmap.cpp b/test/memory/mmap.cpp index abf93ea8d..80d998d23 100644 --- a/test/memory/mmap.cpp +++ b/test/memory/mmap.cpp @@ -703,8 +703,8 @@ BOOST_AUTO_TEST_CASE(mmap__get_capacity__size__expected) constexpr auto expected = 42u; auto ptr = instance.get_capacity(instance.allocate(expected)); - BOOST_CHECK_EQUAL(ptr->size(), expected); - BOOST_CHECK_EQUAL(*ptr->begin(), 0x00u); + BOOST_REQUIRE_EQUAL(ptr->size(), expected); + BOOST_REQUIRE_EQUAL(*ptr->begin(), 0x00u); BOOST_REQUIRE(instance.unload()); ptr.reset(); @@ -723,8 +723,9 @@ BOOST_AUTO_TEST_CASE(mmap__get_raw__always__nonblocking) BOOST_REQUIRE(!instance.load()); constexpr auto expected = 42u; - auto raw = instance.get_raw(instance.allocate(expected)); - BOOST_CHECK_EQUAL(*raw, 0x00u); + const auto raw = instance.get_raw(instance.allocate(expected)); + BOOST_REQUIRE(!is_null(raw)); + BOOST_REQUIRE_EQUAL(*raw, 0x00u); // raw pointer does not block remap. BOOST_REQUIRE(!instance.unload()); From 44caa87ed9c575bfddd4ef989323cae66dd28871 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 17:56:54 -0400 Subject: [PATCH 05/10] Change mmap::get_filled() and get_capacity() to memory object. --- .../database/impl/memory/mmap_dispatch.ipp | 17 +++++++++-------- .../database/impl/primitives/arrayhead.ipp | 6 +++--- .../database/impl/primitives/manager.ipp | 2 +- .../database/impl/primitives/nomap.ipp | 19 +++++++++++++++++++ .../database/memory/interfaces/storage.hpp | 4 ++-- include/bitcoin/database/memory/mmap.hpp | 4 ++-- .../bitcoin/database/primitives/manager.hpp | 2 +- include/bitcoin/database/primitives/nomap.hpp | 3 +++ test/memory/mmap.cpp | 6 +++--- test/mocks/chunk_storage.hpp | 13 ++++++------- test/primitives/manager.cpp | 4 ++-- 11 files changed, 51 insertions(+), 29 deletions(-) diff --git a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp index 2e8df858a..666bf9727 100644 --- a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp +++ b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp @@ -34,10 +34,10 @@ namespace database { // ---------------------------------------------------------------------------- TEMPLATE -memory_ptr CLASS::get_filled(size_t offset, size_t size, +memory CLASS::get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT { - // This is basically allocate(...) for application to a table head. + // This is basically allocate(...), backfilled for use with a table head. { std::unique_lock field_lock(field_mutex_); @@ -67,21 +67,22 @@ memory_ptr CLASS::get_filled(size_t offset, size_t size, logical_ = end; } - return get(offset); + return get1(offset); } TEMPLATE -memory_ptr CLASS::get_capacity(size_t offset) const NOEXCEPT +memory CLASS::get_capacity(size_t offset) const NOEXCEPT { const auto allocated = to_width(capacity()); - const auto ptr = std::make_shared(remap_mutex_); - if (!loaded_ || is_null(ptr)) + memory out{ remap_mutex_ }; + + if (!loaded_) return {}; auto data = memory_map_.front(); - ptr->assign(std::next(data, offset), std::next(data, allocated)); - return ptr; + out.assign(std::next(data, offset), std::next(data, allocated)); + return out; } TEMPLATE diff --git a/include/bitcoin/database/impl/primitives/arrayhead.ipp b/include/bitcoin/database/impl/primitives/arrayhead.ipp index dc2a673f7..b350b9701 100644 --- a/include/bitcoin/database/impl/primitives/arrayhead.ipp +++ b/include/bitcoin/database/impl/primitives/arrayhead.ipp @@ -169,19 +169,19 @@ bool CLASS::push(const Link& link, const Link& index) NOEXCEPT // Allocate as necessary and fill allocations. const auto position = link_to_position(index); const auto ptr = file_.get_filled(position, bucket_size, fill); - if (is_null(ptr)) + if (!ptr) return false; if constexpr (aligned) { // Writes full padded word (0x00 fill). - const auto raw = ptr->data(); + const auto raw = ptr.data(); auto& head = *pointer_cast>(raw); head.store(link, std::memory_order_relaxed); } else { - auto& head = to_array(ptr->data()); + auto& head = to_array(ptr.data()); mutex_.lock(); head = link; diff --git a/include/bitcoin/database/impl/primitives/manager.ipp b/include/bitcoin/database/impl/primitives/manager.ipp index 913676ddb..8efa21cc4 100644 --- a/include/bitcoin/database/impl/primitives/manager.ipp +++ b/include/bitcoin/database/impl/primitives/manager.ipp @@ -102,7 +102,7 @@ inline memory::iterator CLASS::get_raw1(const Link& link) const NOEXCEPT TEMPLATE template > -inline memory_ptr CLASS::get_capacity(const Link& link) const NOEXCEPT +inline memory CLASS::get_capacity(const Link& link) const NOEXCEPT { if (link.is_terminal()) return {}; diff --git a/include/bitcoin/database/impl/primitives/nomap.ipp b/include/bitcoin/database/impl/primitives/nomap.ipp index f3b68090c..cf769b4cc 100644 --- a/include/bitcoin/database/impl/primitives/nomap.ipp +++ b/include/bitcoin/database/impl/primitives/nomap.ipp @@ -234,6 +234,25 @@ bool CLASS::put(const memory_ptr& ptr, const Element& element) NOEXCEPT return element.to_data(sink); } +TEMPLATE +template > +bool CLASS::put(memory&& ptr, const Element& element) NOEXCEPT +{ + using namespace system; + if (!ptr) + return false; + + iostream stream{ ptr }; + flipper sink{ stream }; + + if constexpr (!is_slab) + { + BC_DEBUG_ONLY(sink.set_limit(Size * element.count());) + } + + return element.to_data(sink); +} + TEMPLATE template > inline bool CLASS::put_link(Link& link, const Element& element) NOEXCEPT diff --git a/include/bitcoin/database/memory/interfaces/storage.hpp b/include/bitcoin/database/memory/interfaces/storage.hpp index 169e2e30b..e5f5736eb 100644 --- a/include/bitcoin/database/memory/interfaces/storage.hpp +++ b/include/bitcoin/database/memory/interfaces/storage.hpp @@ -89,12 +89,12 @@ class storage virtual size_t allocate(size_t count) NOEXCEPT = 0; /// Get remap-protected r/w access to offset (or null) allocated to size. - virtual memory_ptr get_filled(size_t offset, size_t size, + virtual memory get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT = 0; /// Get remap-protected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within full capacity. - virtual memory_ptr get_capacity(size_t offset=zero) const NOEXCEPT = 0; + virtual memory get_capacity(size_t offset=zero) const NOEXCEPT = 0; /// Get unprotected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within full capacity. diff --git a/include/bitcoin/database/memory/mmap.hpp b/include/bitcoin/database/memory/mmap.hpp index 51f203bcd..87d2fcb3f 100644 --- a/include/bitcoin/database/memory/mmap.hpp +++ b/include/bitcoin/database/memory/mmap.hpp @@ -132,11 +132,11 @@ class mmap size_t allocate(size_t count) NOEXCEPT override; /// Remap-protected r/w access to offset (or null) allocated to size. - memory_ptr get_filled(size_t offset, size_t size, + memory get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT override; /// Remap-protected r/w access to start/offset (or null), within capacity. - memory_ptr get_capacity(size_t offset=zero) const NOEXCEPT override; + memory get_capacity(size_t offset=zero) const NOEXCEPT override; /// Unprotected r/w access to start/offset (or null), within logical. memory::iterator get_raw(size_t offset=zero) const NOEXCEPT override; diff --git a/include/bitcoin/database/primitives/manager.hpp b/include/bitcoin/database/primitives/manager.hpp index 6f9cbbeb0..8dc11c154 100644 --- a/include/bitcoin/database/primitives/manager.hpp +++ b/include/bitcoin/database/primitives/manager.hpp @@ -59,7 +59,7 @@ class managers /// Return memory object (limited to AoS) within capacity. template = true> - inline memory_ptr get_capacity(const Link& link) const NOEXCEPT; + inline memory get_capacity(const Link& link) const NOEXCEPT; /// Manage shared multi-backed byte storage device (caller owns storage). managers(storage& body) NOEXCEPT; diff --git a/include/bitcoin/database/primitives/nomap.hpp b/include/bitcoin/database/primitives/nomap.hpp index 07892c9b9..b88d1d2d2 100644 --- a/include/bitcoin/database/primitives/nomap.hpp +++ b/include/bitcoin/database/primitives/nomap.hpp @@ -122,6 +122,9 @@ class nomap template = true> bool put(const memory_ptr& ptr, const Element& element) NOEXCEPT; + template = true> + bool put(memory&& ptr, const Element& element) NOEXCEPT; + /// Put element and return link. template = true> bool put_link(Link& link, const Element& element) NOEXCEPT; diff --git a/test/memory/mmap.cpp b/test/memory/mmap.cpp index 80d998d23..875e1e4d4 100644 --- a/test/memory/mmap.cpp +++ b/test/memory/mmap.cpp @@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_capacity) BOOST_REQUIRE(memory); const auto expected = std::next(instance.get()->data(), offset); - BOOST_REQUIRE(memory->data() == expected); + BOOST_REQUIRE(memory.data() == expected); constexpr auto capacity = offset + size + to_half(offset + size); BOOST_REQUIRE_EQUAL(instance.capacity(), capacity); @@ -703,8 +703,8 @@ BOOST_AUTO_TEST_CASE(mmap__get_capacity__size__expected) constexpr auto expected = 42u; auto ptr = instance.get_capacity(instance.allocate(expected)); - BOOST_REQUIRE_EQUAL(ptr->size(), expected); - BOOST_REQUIRE_EQUAL(*ptr->begin(), 0x00u); + BOOST_REQUIRE_EQUAL(ptr.size(), expected); + BOOST_REQUIRE_EQUAL(*ptr.begin(), 0x00u); BOOST_REQUIRE(instance.unload()); ptr.reset(); diff --git a/test/mocks/chunk_storage.hpp b/test/mocks/chunk_storage.hpp index cf0433766..bedb3382b 100644 --- a/test/mocks/chunk_storage.hpp +++ b/test/mocks/chunk_storage.hpp @@ -240,7 +240,7 @@ class chunk_storages // access // ------------------------------------------------------------------------ - memory_ptr get_filled(size_t offset, size_t size, + memory get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT override { { @@ -259,16 +259,15 @@ class chunk_storages logical_ = (minimum / widths[0]); } - return get(offset); + return get1(offset); } - memory_ptr get_capacity(size_t offset=zero) const NOEXCEPT override + memory get_capacity(size_t offset=zero) const NOEXCEPT override { - using namespace system; auto& buffer = at(zero); - const auto ptr = emplace_shared(map_mutex_); - ptr->assign(get_raw(offset), std::next(buffer.data(), buffer.size())); - return ptr; + accessor out{ map_mutex_ }; + out.assign(get_raw(offset), std::next(buffer.data(), buffer.size())); + return out; } memory::iterator get_raw(size_t offset=zero) const NOEXCEPT override diff --git a/test/primitives/manager.cpp b/test/primitives/manager.cpp index 8c7fc3cd4..b88b28e09 100644 --- a/test/primitives/manager.cpp +++ b/test/primitives/manager.cpp @@ -375,8 +375,8 @@ BOOST_AUTO_TEST_CASE(manager__get_capacity__record__expected) manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.get(1)->size(), expected); - BOOST_REQUIRE_EQUAL(*instance.get_capacity(0)->begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get_capacity(1)->begin(), 0x06_u8); + BOOST_REQUIRE_EQUAL(*instance.get_capacity(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get_capacity(1).begin(), 0x06_u8); BOOST_REQUIRE(!instance.get_fault()); } From 602ca908ffdcdf9e514a8e0de505891f40b36e21 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 17:57:00 -0400 Subject: [PATCH 06/10] Style. --- include/bitcoin/database/impl/primitives/nomap.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bitcoin/database/impl/primitives/nomap.ipp b/include/bitcoin/database/impl/primitives/nomap.ipp index cf769b4cc..8e7846b80 100644 --- a/include/bitcoin/database/impl/primitives/nomap.ipp +++ b/include/bitcoin/database/impl/primitives/nomap.ipp @@ -270,7 +270,7 @@ inline Link CLASS::put_link(const Element& element) NOEXCEPT return put_link(link, element) ? link : Link{}; } -/// NOT THREAD SAFE (used only for height index with writer ordering). +// NOT THREAD SAFE (used only for height index with writer ordering). TEMPLATE template > inline bool CLASS::commit(const Element& element) NOEXCEPT From f11bd68bd6278a5b9d8251baa2e4b0a8f9af7400 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 17:57:32 -0400 Subject: [PATCH 07/10] Guard nomaps::put() write extent. --- include/bitcoin/database/impl/primitives/nomaps.ipp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/bitcoin/database/impl/primitives/nomaps.ipp b/include/bitcoin/database/impl/primitives/nomaps.ipp index 39f59c2c9..8e3b2257d 100644 --- a/include/bitcoin/database/impl/primitives/nomaps.ipp +++ b/include/bitcoin/database/impl/primitives/nomaps.ipp @@ -198,7 +198,8 @@ bool CLASS::put(memory::iterator it, const Element& element) NOEXCEPT return false; using namespace system; - iostream stream{ it, system::maximum }; + const auto bytes = width * element.count(); + iostream stream{ it, possible_narrow_and_sign_cast(bytes) }; flipper sink{ stream }; BC_DEBUG_ONLY(sink.set_limit(width * element.count());) From bb0c614fe6ca9d1182d6999c67e0c0b4a9829913 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 18:56:39 -0400 Subject: [PATCH 08/10] Remove shared_ptr from all memory allocator emissions. --- .../database/impl/memory/mmap_dispatch.ipp | 8 --- .../database/impl/memory/mmap_storage.ipp | 4 +- .../database/impl/primitives/arrayhead.ipp | 20 +++---- .../database/impl/primitives/arraymap.ipp | 8 +-- .../database/impl/primitives/hashhead.ipp | 14 ++--- .../database/impl/primitives/hashmap.ipp | 52 +++++++++---------- .../database/impl/primitives/iterator.ipp | 26 +++++----- .../database/impl/primitives/manager.ipp | 34 ------------ .../database/impl/primitives/nohead.ipp | 12 ++--- .../database/impl/primitives/nomap.ipp | 34 +++--------- include/bitcoin/database/memory/accessor.hpp | 2 - include/bitcoin/database/memory/finalizer.hpp | 2 +- .../database/memory/interfaces/storage.hpp | 4 -- include/bitcoin/database/memory/mmap.hpp | 3 -- .../bitcoin/database/primitives/hashmap.hpp | 35 ++++++------- .../bitcoin/database/primitives/iterator.hpp | 18 +++---- .../bitcoin/database/primitives/manager.hpp | 4 -- include/bitcoin/database/primitives/nomap.hpp | 9 ++-- test/memory/mmap.cpp | 28 +++++----- test/mocks/chunk_storage.hpp | 5 -- test/primitives/arrayhead.cpp | 23 ++++---- test/primitives/hashhead.cpp | 4 +- test/primitives/iterator.cpp | 12 ++--- test/primitives/manager.cpp | 24 ++++----- test/primitives/nohead.cpp | 23 ++++---- 25 files changed, 162 insertions(+), 246 deletions(-) diff --git a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp index 666bf9727..887ba4022 100644 --- a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp +++ b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp @@ -102,14 +102,6 @@ memory::iterator CLASS::get_at_raw(size_t column, size_t offset) const NOEXCEPT return std::next(memory_map_.at(column), offset); } -TEMPLATE -memory_ptr CLASS::get(size_t offset) const NOEXCEPT -{ - auto out = get_at1(zero, offset); - if (!out) return {}; - return std::make_shared(std::move(out)); -} - TEMPLATE memory CLASS::get1(size_t offset) const NOEXCEPT { diff --git a/include/bitcoin/database/impl/memory/mmap_storage.ipp b/include/bitcoin/database/impl/memory/mmap_storage.ipp index fd348bfad..9a233292a 100644 --- a/include/bitcoin/database/impl/memory/mmap_storage.ipp +++ b/include/bitcoin/database/impl/memory/mmap_storage.ipp @@ -255,11 +255,11 @@ TEMPLATE code CLASS::dump(const std::filesystem::path& path) const NOEXCEPT { BC_ASSERT(is_one(columns)); - const auto ptr = get(); + const auto ptr = get1(); if (!ptr) return error::unloaded_file; - return file::create_file_ex(path, ptr->begin(), ptr->size()); + return file::create_file_ex(path, ptr.begin(), ptr.size()); } // ---------------------------------------------------------------------------- diff --git a/include/bitcoin/database/impl/primitives/arrayhead.ipp b/include/bitcoin/database/impl/primitives/arrayhead.ipp index b350b9701..d079794a2 100644 --- a/include/bitcoin/database/impl/primitives/arrayhead.ipp +++ b/include/bitcoin/database/impl/primitives/arrayhead.ipp @@ -63,7 +63,7 @@ inline Link CLASS::index(size_t key) const NOEXCEPT TEMPLATE bool CLASS::clear() NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr) return false; @@ -71,7 +71,7 @@ bool CLASS::clear() NOEXCEPT // count to zero, which is picked up in arraymap::reset(). Body file size // remains unchanged and subject to initialization size at each startup. So // there is no reduction until restart, which can include config change. - std::fill_n(ptr->data(), size(), system::bit_all); + std::fill_n(ptr.data(), size(), system::bit_all); return set_body_count(zero); } @@ -98,28 +98,28 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE bool CLASS::get_body_count(Link& count) const NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr || Link::size > size()) return false; // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - count = to_array(ptr->data()); + count = to_array(ptr.data()); return true; } TEMPLATE bool CLASS::set_body_count(const Link& count) NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr || Link::size > size()) return false; // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - to_array(ptr->data()) = count; + to_array(ptr.data()) = count; return true; } @@ -137,14 +137,14 @@ Link CLASS::at(size_t key) const NOEXCEPT if (position >= size()) return {}; - const auto ptr = file_.get(position); - if (is_null(ptr)) + const auto ptr = file_.get1(position); + if (!ptr) return {}; if constexpr (aligned) { // Reads full padded word. - const auto raw = ptr->data(); + const auto raw = ptr.data(); const auto& head = *pointer_cast>(raw); // Aligned values must be masked to match terminal. @@ -152,7 +152,7 @@ Link CLASS::at(size_t key) const NOEXCEPT } else { - const auto& head = to_array(ptr->data()); + const auto& head = to_array(ptr.data()); mutex_.lock_shared(); const auto top = head; mutex_.unlock_shared(); diff --git a/include/bitcoin/database/impl/primitives/arraymap.ipp b/include/bitcoin/database/impl/primitives/arraymap.ipp index b37a898b1..548901a8a 100644 --- a/include/bitcoin/database/impl/primitives/arraymap.ipp +++ b/include/bitcoin/database/impl/primitives/arraymap.ipp @@ -174,12 +174,12 @@ TEMPLATE ELEMENT_CONSTRAINT inline bool CLASS::get(const Link& link, Element& element) const NOEXCEPT { - const auto ptr = body_.get(link); + const auto ptr = body_.get1(link); if (!ptr) return false; using namespace system; - iostream stream{ *ptr }; + iostream stream{ ptr }; reader source{ stream }; if constexpr (!is_slab) { BC_DEBUG_ONLY(source.set_limit(RowSize * element.count());) } @@ -195,13 +195,13 @@ bool CLASS::put(size_t key, const Element& element) NOEXCEPT return false; const auto link = body_.allocate(element.count()); - const auto ptr = body_.get(link); + const auto ptr = body_.get1(link); if (!ptr) return false; // iostream.flush is a nop (direct copy). using namespace system; - iostream stream{ *ptr }; + iostream stream{ ptr }; finalizer sink{ stream }; if constexpr (!is_slab) { BC_DEBUG_ONLY(sink.set_limit(RowSize * element.count());) } diff --git a/include/bitcoin/database/impl/primitives/hashhead.ipp b/include/bitcoin/database/impl/primitives/hashhead.ipp index 6858e2324..924e99bee 100644 --- a/include/bitcoin/database/impl/primitives/hashhead.ipp +++ b/include/bitcoin/database/impl/primitives/hashhead.ipp @@ -64,15 +64,15 @@ bool CLASS::create() NOEXCEPT if (start == storage::eof) return false; - const auto ptr = file_.get(start); + const auto ptr = file_.get1(start); if (!ptr) return false; BC_ASSERT_MSG(verify(), "unexpected head size"); // std::memset/fill_n have identical performance (on win32). - ////std::memset(ptr->data(), system::bit_all, allocation); - std::fill_n(ptr->data(), allocation, system::bit_all); + ////std::memset(ptr.data(), system::bit_all, allocation); + std::fill_n(ptr.data(), allocation, system::bit_all); return set_body_count(zero); } @@ -85,21 +85,21 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE bool CLASS::get_body_count(Link& count) const NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr) return false; // Body count is written as the first value in link size, but since // offsetting is a multiple of sell size, a full cell is consumed for it. // In case of disabled there are no cells, so file is link size. - link_array(count.value) = link_array(ptr->data()); + link_array(count.value) = link_array(ptr.data()); return true; } TEMPLATE bool CLASS::set_body_count(const Link& count) NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr) return false; @@ -107,7 +107,7 @@ bool CLASS::set_body_count(const Link& count) NOEXCEPT // offsetting is a multiple of sell size, a full cell is consumed for it. // In case of disabled there are no cells, so file is link size. auto value = count.value; - link_array(ptr->data()) = link_array(value); + link_array(ptr.data()) = link_array(value); return true; } diff --git a/include/bitcoin/database/impl/primitives/hashmap.ipp b/include/bitcoin/database/impl/primitives/hashmap.ipp index f15e87b6e..3435d2067 100644 --- a/include/bitcoin/database/impl/primitives/hashmap.ipp +++ b/include/bitcoin/database/impl/primitives/hashmap.ipp @@ -165,7 +165,7 @@ inline Link CLASS::top(const Link& link) const NOEXCEPT } TEMPLATE -inline bool CLASS::exists(const memory_ptr& ptr, const Key& key) const NOEXCEPT +inline bool CLASS::exists(const memory& ptr, const Key& key) const NOEXCEPT { return !first(ptr, key).is_terminal(); } @@ -177,7 +177,7 @@ inline bool CLASS::exists(const Key& key) const NOEXCEPT } TEMPLATE -inline Link CLASS::first(const memory_ptr& ptr, const Key& key) const NOEXCEPT +inline Link CLASS::first(const memory& ptr, const Key& key) const NOEXCEPT { return first(ptr, head_.top(key), key); } @@ -208,20 +208,20 @@ inline Link CLASS::allocate(const Link& size) NOEXCEPT } TEMPLATE -inline memory_ptr CLASS::get_memory() const NOEXCEPT +inline memory CLASS::get_memory() const NOEXCEPT { - return body_.get(); + return body_.get1(); } TEMPLATE Key CLASS::get_key(const Link& link) NOEXCEPT { using namespace system; - const auto ptr = body_.get(link); - if (!ptr || is_lesser(ptr->size(), index_size)) + const auto ptr = body_.get1(link); + if (!ptr || is_lesser(ptr.size(), index_size)) return {}; - return unsafe_array_cast(std::next(ptr->begin(), + return unsafe_array_cast(std::next(ptr.begin(), Link::size)); } @@ -236,7 +236,7 @@ TEMPLATE ELEMENT_CONSTRAINT inline Link CLASS::find_link(const Key& key, Element& element) const NOEXCEPT { - // This override avoids duplicated memory_ptr construct in get(first()). + // This override avoids duplicated memory construct in get(first()). const auto ptr = get_memory(); const auto link = first(ptr, head_.top(key), key); if (link.is_terminal()) @@ -256,7 +256,7 @@ inline bool CLASS::get(const Link& link, Element& element) const NOEXCEPT // static TEMPLATE ELEMENT_CONSTRAINT -inline bool CLASS::get(const memory_ptr& ptr, const Link& link, +inline bool CLASS::get(const memory& ptr, const Link& link, Element& element) NOEXCEPT { return read(ptr, link, element); @@ -284,7 +284,7 @@ inline bool CLASS::get(const iterator& it, const Link& link, // static TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::set(const memory_ptr& ptr, const Link& link, const Key& key, +bool CLASS::set(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { using namespace system; @@ -295,13 +295,13 @@ bool CLASS::set(const memory_ptr& ptr, const Link& link, const Key& key, if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; // Stream starts at record and the index is skipped for reader convenience. - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; @@ -383,7 +383,7 @@ inline bool CLASS::put(const Link& link, const Key& key, TEMPLATE ELEMENT_CONSTRAINT -inline bool CLASS::put(const memory_ptr& ptr, const Link& link, const Key& key, +inline bool CLASS::put(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { return write(ptr, link, key, element); @@ -391,7 +391,7 @@ inline bool CLASS::put(const memory_ptr& ptr, const Link& link, const Key& key, TEMPLATE ELEMENT_CONSTRAINT -inline bool CLASS::put(bool& duplicate, const memory_ptr& ptr, +inline bool CLASS::put(bool& duplicate, const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { Link previous{}; @@ -429,7 +429,7 @@ inline bool CLASS::commit(const Link& link, const Key& key) NOEXCEPT } TEMPLATE -bool CLASS::commit(const memory_ptr& ptr, const Link& link, +bool CLASS::commit(const memory& ptr, const Link& link, const Key& key) NOEXCEPT { using namespace system; @@ -437,7 +437,7 @@ bool CLASS::commit(const memory_ptr& ptr, const Link& link, return false; // get element offset (fault) - const auto offset = ptr->offset(body::link_to_position(link)); + const auto offset = ptr.offset(body::link_to_position(link)); if (is_null(offset)) return false; @@ -451,8 +451,7 @@ bool CLASS::commit(const memory_ptr& ptr, const Link& link, // static TEMPLATE -Link CLASS::first(const memory_ptr& ptr, const Link& link, - const Key& key) NOEXCEPT +Link CLASS::first(const memory& ptr, const Link& link, const Key& key) NOEXCEPT { using namespace system; if (!ptr) @@ -462,7 +461,7 @@ Link CLASS::first(const memory_ptr& ptr, const Link& link, while (!next.is_terminal()) { // get element offset (fault) - const auto offset = ptr->offset(body::link_to_position(next)); + const auto offset = ptr.offset(body::link_to_position(next)); if (is_null(offset)) return {}; @@ -481,8 +480,7 @@ Link CLASS::first(const memory_ptr& ptr, const Link& link, // static TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::read(const memory_ptr& ptr, const Link& link, - Element& element) NOEXCEPT +bool CLASS::read(const memory& ptr, const Link& link, Element& element) NOEXCEPT { using namespace system; if (!ptr || link.is_terminal()) @@ -492,12 +490,12 @@ bool CLASS::read(const memory_ptr& ptr, const Link& link, if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; @@ -512,7 +510,7 @@ bool CLASS::read(const memory_ptr& ptr, const Link& link, TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::write(const memory_ptr& ptr, const Link& link, const Key& key, +bool CLASS::write(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { Link unused{}; @@ -521,7 +519,7 @@ bool CLASS::write(const memory_ptr& ptr, const Link& link, const Key& key, TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::write(Link& previous, const memory_ptr& ptr, const Link& link, +bool CLASS::write(Link& previous, const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { using namespace system; @@ -532,12 +530,12 @@ bool CLASS::write(Link& previous, const memory_ptr& ptr, const Link& link, if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; diff --git a/include/bitcoin/database/impl/primitives/iterator.ipp b/include/bitcoin/database/impl/primitives/iterator.ipp index 7db4b1125..f7ec7695c 100644 --- a/include/bitcoin/database/impl/primitives/iterator.ipp +++ b/include/bitcoin/database/impl/primitives/iterator.ipp @@ -28,14 +28,14 @@ namespace libbitcoin { namespace database { TEMPLATE -CLASS::iterator(memory_ptr&& data, const Link& start, Key&& key) NOEXCEPT +CLASS::iterator(memory&& data, const Link& start, Key&& key) NOEXCEPT : memory_(std::move(data)), key_(std::forward(key)), link_(to_first(start)) { } TEMPLATE -CLASS::iterator(memory_ptr&& data, const Link& start, const Key& key) NOEXCEPT +CLASS::iterator(memory&& data, const Link& start, const Key& key) NOEXCEPT : memory_(std::move(data)), key_(key), link_(to_first(start)) { } @@ -59,7 +59,7 @@ inline const Link& CLASS::get() const NOEXCEPT } TEMPLATE -inline const memory_ptr& CLASS::ptr() const NOEXCEPT +inline const memory& CLASS::ptr() const NOEXCEPT { return memory_; } @@ -99,13 +99,13 @@ inline CLASS& CLASS::operator++() NOEXCEPT return *this; } -TEMPLATE -inline CLASS CLASS::operator++(int) NOEXCEPT -{ - auto previous = *this; - ++(*this); - return previous; -} +////TEMPLATE +////inline CLASS CLASS::operator++(int) NOEXCEPT +////{ +//// auto previous = *this; +//// ++(*this); +//// return previous; +////} // protected // ---------------------------------------------------------------------------- @@ -120,7 +120,7 @@ Link CLASS::to_first(Link link) const NOEXCEPT while (!link.is_terminal()) { // get element offset (fault) - const auto offset = memory_->offset(manager::link_to_position(link)); + const auto offset = memory_.offset(manager::link_to_position(link)); if (is_null(offset)) return Link::terminal; @@ -142,7 +142,7 @@ Link CLASS::to_next(Link link) const NOEXCEPT while (!link.is_terminal()) { // get element offset (fault) - auto offset = memory_->offset(manager::link_to_position(link)); + auto offset = memory_.offset(manager::link_to_position(link)); if (is_null(offset)) return Link::terminal; @@ -152,7 +152,7 @@ Link CLASS::to_next(Link link) const NOEXCEPT return link; // get next element offset (fault) - offset = memory_->offset(manager::link_to_position(link)); + offset = memory_.offset(manager::link_to_position(link)); if (is_null(offset)) return Link::terminal; diff --git a/include/bitcoin/database/impl/primitives/manager.ipp b/include/bitcoin/database/impl/primitives/manager.ipp index 8efa21cc4..3f4663328 100644 --- a/include/bitcoin/database/impl/primitives/manager.ipp +++ b/include/bitcoin/database/impl/primitives/manager.ipp @@ -24,20 +24,6 @@ namespace libbitcoin { namespace database { -TEMPLATE -template -inline memory_ptr CLASS::get() const NOEXCEPT -{ - if constexpr (is_one(columns)) - return files_.get(); - else - { - auto out = files_.get_at1(Column); - if (!out) return {}; - return std::make_shared(std::move(out)); - } -} - TEMPLATE template inline memory CLASS::get1() const NOEXCEPT @@ -48,26 +34,6 @@ inline memory CLASS::get1() const NOEXCEPT return files_.get_at1(Column); } -TEMPLATE -template -inline memory_ptr CLASS::get(const Link& link) const NOEXCEPT -{ - if (link.is_terminal()) - return {}; - - const auto position = link_to_position(link); - - // memory.size() may be negative (stream treats as exhausted). - if constexpr (is_one(columns)) - return files_.get(position); - else - { - auto out = files_.get_at1(Column, position); - if (!out) return {}; - return std::make_shared(std::move(out)); - } -} - TEMPLATE template inline memory CLASS::get1(const Link& link) const NOEXCEPT diff --git a/include/bitcoin/database/impl/primitives/nohead.ipp b/include/bitcoin/database/impl/primitives/nohead.ipp index 67693beca..adfa31427 100644 --- a/include/bitcoin/database/impl/primitives/nohead.ipp +++ b/include/bitcoin/database/impl/primitives/nohead.ipp @@ -55,7 +55,7 @@ bool CLASS::enabled() const NOEXCEPT TEMPLATE bool CLASS::clear() NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr) return false; @@ -63,7 +63,7 @@ bool CLASS::clear() NOEXCEPT // count to zero, which is picked up in arraymap::reset(). Body file size // remains unchanged and subject to initialization size at each startup. So // there is no reduction until restart, which can include config change. - std::fill_n(ptr->data(), size(), system::bit_all); + std::fill_n(ptr.data(), size(), system::bit_all); return set_body_count(zero); } @@ -90,28 +90,28 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE bool CLASS::get_body_count(Link& count) const NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr || Link::size > size()) return false; // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - count = to_array(ptr->data()); + count = to_array(ptr.data()); return true; } TEMPLATE bool CLASS::set_body_count(const Link& count) NOEXCEPT { - const auto ptr = file_.get(); + const auto ptr = file_.get1(); if (!ptr || Link::size > size()) return false; // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - to_array(ptr->data()) = count; + to_array(ptr.data()) = count; return true; } diff --git a/include/bitcoin/database/impl/primitives/nomap.ipp b/include/bitcoin/database/impl/primitives/nomap.ipp index 8e7846b80..832012a4a 100644 --- a/include/bitcoin/database/impl/primitives/nomap.ipp +++ b/include/bitcoin/database/impl/primitives/nomap.ipp @@ -128,9 +128,9 @@ bool CLASS::reserve(const Link& size) NOEXCEPT } TEMPLATE -memory_ptr CLASS::get_memory() const NOEXCEPT +memory CLASS::get_memory() const NOEXCEPT { - return manager_.get(); + return manager_.get1(); } // error condition @@ -160,8 +160,7 @@ code CLASS::reload() NOEXCEPT // static TEMPLATE template > -bool CLASS::get(const memory_ptr& ptr, const Link& link, - Element& element) NOEXCEPT +bool CLASS::get(const memory& ptr, const Link& link, Element& element) NOEXCEPT { using namespace system; if (!ptr || link.is_terminal()) @@ -171,12 +170,12 @@ bool CLASS::get(const memory_ptr& ptr, const Link& link, if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; @@ -211,32 +210,13 @@ template > bool CLASS::put(const Link& link, const Element& element) NOEXCEPT { using namespace system; - const auto ptr = manager_.get(link); + const auto ptr = manager_.get1(link); return put(ptr, element); } TEMPLATE template > -bool CLASS::put(const memory_ptr& ptr, const Element& element) NOEXCEPT -{ - using namespace system; - if (!ptr) - return false; - - iostream stream{ *ptr }; - flipper sink{ stream }; - - if constexpr (!is_slab) - { - BC_DEBUG_ONLY(sink.set_limit(Size * element.count());) - } - - return element.to_data(sink); -} - -TEMPLATE -template > -bool CLASS::put(memory&& ptr, const Element& element) NOEXCEPT +bool CLASS::put(const memory& ptr, const Element& element) NOEXCEPT { using namespace system; if (!ptr) diff --git a/include/bitcoin/database/memory/accessor.hpp b/include/bitcoin/database/memory/accessor.hpp index 8dfda4a4f..63c782982 100644 --- a/include/bitcoin/database/memory/accessor.hpp +++ b/include/bitcoin/database/memory/accessor.hpp @@ -33,7 +33,6 @@ class accessor final typedef uint8_t value_type; typedef value_type* iterator; typedef const value_type* const_iterator; - typedef std::shared_ptr ptr; DELETE_COPY(accessor); DEFAULT_MOVE(accessor); @@ -127,7 +126,6 @@ class accessor final }; using memory = accessor; -using memory_ptr = accessor::ptr; } // namespace database } // namespace libbitcoin diff --git a/include/bitcoin/database/memory/finalizer.hpp b/include/bitcoin/database/memory/finalizer.hpp index a39169064..1146be5f5 100644 --- a/include/bitcoin/database/memory/finalizer.hpp +++ b/include/bitcoin/database/memory/finalizer.hpp @@ -65,7 +65,7 @@ class finalizer_ finalization finalize_; }; -/// A finalizing byte reader/writer that copies data from/to a memory_ptr. +/// A finalizing byte reader/writer that copies data from/to a memory object. using finalizer = finalizer_<>; BC_POP_WARNING() diff --git a/include/bitcoin/database/memory/interfaces/storage.hpp b/include/bitcoin/database/memory/interfaces/storage.hpp index e5f5736eb..677078bdc 100644 --- a/include/bitcoin/database/memory/interfaces/storage.hpp +++ b/include/bitcoin/database/memory/interfaces/storage.hpp @@ -105,10 +105,6 @@ class storage virtual memory::iterator get_at_raw(size_t column, size_t offset=zero) const NOEXCEPT = 0; - /// Get remap-protected r/w access to start/offset of memory map (or null). - /// Pointer is constrained to starting write within logical allocation. - virtual memory_ptr get(size_t offset=zero) const NOEXCEPT = 0; - /// Get remap-protected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within logical allocation. virtual memory get1(size_t offset=zero) const NOEXCEPT = 0; diff --git a/include/bitcoin/database/memory/mmap.hpp b/include/bitcoin/database/memory/mmap.hpp index 87d2fcb3f..f0cabfc08 100644 --- a/include/bitcoin/database/memory/mmap.hpp +++ b/include/bitcoin/database/memory/mmap.hpp @@ -145,9 +145,6 @@ class mmap memory::iterator get_at_raw(size_t column, size_t offset=zero) const NOEXCEPT override; - /// Remap-protected r/w access to start/offset (or null), within logical. - memory_ptr get(size_t offset=zero) const NOEXCEPT override; - /// Remap-protected r/w access to start/offset (or null), within logical. memory get1(size_t offset=zero) const NOEXCEPT override; diff --git a/include/bitcoin/database/primitives/hashmap.hpp b/include/bitcoin/database/primitives/hashmap.hpp index ab245a321..69dd41362 100644 --- a/include/bitcoin/database/primitives/hashmap.hpp +++ b/include/bitcoin/database/primitives/hashmap.hpp @@ -109,11 +109,11 @@ class hashmap inline Link top(const Link& list) const NOEXCEPT; /// True if an instance of object with key exists. - inline bool exists(const memory_ptr& ptr, const Key& key) const NOEXCEPT; + inline bool exists(const memory& ptr, const Key& key) const NOEXCEPT; inline bool exists(const Key& key) const NOEXCEPT; /// Return first element link or terminal if not found/error. - inline Link first(const memory_ptr& ptr, const Key& key) const NOEXCEPT; + inline Link first(const memory& ptr, const Key& key) const NOEXCEPT; inline Link first(const Key& key) const NOEXCEPT; /// Iterator holds shared lock on storage remap. @@ -124,7 +124,7 @@ class hashmap inline Link allocate(const Link& size) NOEXCEPT; /// Return ptr for batch processing, holds shared lock on storage remap. - inline memory_ptr get_memory() const NOEXCEPT; + inline memory get_memory() const NOEXCEPT; /// Return the associated search key (terminal link returns default). Key get_key(const Link& link) NOEXCEPT; @@ -143,7 +143,7 @@ class hashmap /// Get element at link using get_memory() ptr, false if deserialize error. template = true> - static inline bool get(const memory_ptr& ptr, const Link& link, + static inline bool get(const memory& ptr, const Link& link, Element& element) NOEXCEPT; /// Get element at link, false if deserialize error. @@ -158,7 +158,7 @@ class hashmap /// Set element into previously allocated link (follow with commit). template = true> - static bool set(const memory_ptr& ptr, const Link& link, const Key& key, + static bool set(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT; /// Set element into previously allocated link (follow with commit). @@ -190,39 +190,38 @@ class hashmap /// Set/commit allocated element at link to key, using get_memory() ptr. template = true> - inline bool put(const memory_ptr& ptr, const Link& link, + inline bool put(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT; /// Set/commit allocated element at link to key, using get_memory() ptr. template = true> - inline bool put(bool& duplicate, const memory_ptr& ptr, - const Link& link, const Key& key, const Element& element) NOEXCEPT; + inline bool put(bool& duplicate, const memory& ptr, const Link& link, + const Key& key, const Element& element) NOEXCEPT; /// Commit previously set element at link to key. inline Link commit_link(const Link& link, const Key& key) NOEXCEPT; inline bool commit(const Link& link, const Key& key) NOEXCEPT; - bool commit(const memory_ptr& ptr, const Link& link, - const Key& key) NOEXCEPT; + bool commit(const memory& ptr, const Link& link, const Key& key) NOEXCEPT; protected: - /// memory_ptr parameter must be from start (i.e. from get_memory()). + /// memory parameter must be from start (i.e. from get_memory()). /// Get first element matching key, from top link and whole table memory. - static Link first(const memory_ptr& ptr, const Link& link, + static Link first(const memory& ptr, const Link& link, const Key& key) NOEXCEPT; - /// memory_ptr parameter must be from start (i.e. from get_memory()). + /// memory parameter must be from start (i.e. from get_memory()). /// Get element at link using memory object, false if deserialize error. template = true> - static bool read(const memory_ptr& ptr, const Link& link, + static bool read(const memory& ptr, const Link& link, Element& element) NOEXCEPT; - /// memory_ptr parameter must be from start (i.e. from get_memory()). + /// memory parameter must be from start (i.e. from get_memory()). /// Set and commit previously allocated element at link to key. template = true> - bool write(const memory_ptr& ptr, const Link& link, - const Key& key, const Element& element) NOEXCEPT; + bool write(const memory& ptr, const Link& link, const Key& key, + const Element& element) NOEXCEPT; template = true> - bool write(Link& previous, const memory_ptr& ptr, const Link& link, + bool write(Link& previous, const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT; private: diff --git a/include/bitcoin/database/primitives/iterator.hpp b/include/bitcoin/database/primitives/iterator.hpp index a735a7b37..44df7f4e2 100644 --- a/include/bitcoin/database/primitives/iterator.hpp +++ b/include/bitcoin/database/primitives/iterator.hpp @@ -27,8 +27,8 @@ namespace libbitcoin { namespace database { -/// THIS HOLDS A memory_ptr WHICH HOLDS A SHARED REMAP LOCK. IT SHOULD NOT BE -/// HELD WHILE THE HOLDING CODE EXECUTES READS AGAINST THE SAME TABLE. +/// THIS HOLDS A memory object WHICH HOLDS A SHARED REMAP LOCK. IT SHOULD NOT +/// BE HELD WHILE THE HOLDING CODE EXECUTES READS AGAINST THE SAME TABLE. /// OTHERWISE A DEADLOCK WILL OCCUR WHEN THE TABLE'S FILE IS EXPANDED, WHICH /// WAITS ON THE RELEASE OF THE SHARED LOCK (REMAP REQUIRES EXCLUSIVE ACCESS). /// THE hashmap.get(const iterator& it, ...) METHOD EXISTS TO PREVENT A CALL TO @@ -52,8 +52,8 @@ class iterator static constexpr bool end() NOEXCEPT { return false; } /// This advances to first match (or terminal). - iterator(memory_ptr&& data, const Link& start, Key&& key) NOEXCEPT; - iterator(memory_ptr&& data, const Link& start, const Key& key) NOEXCEPT; + iterator(memory&& data, const Link& start, Key&& key) NOEXCEPT; + iterator(memory&& data, const Link& start, const Key& key) NOEXCEPT; /// Advance to next and return false if none found. inline bool advance() NOEXCEPT; @@ -64,10 +64,10 @@ class iterator /// Return current link, terminal if not found. inline const Link& get() const NOEXCEPT; - /// Access the underlying memory pointer. - inline const memory_ptr& ptr() const NOEXCEPT; + /// Access the underlying memory reference. + inline const memory& ptr() const NOEXCEPT; - /// Release the memory pointer, invalidates iterator. + /// Release the memory reference, invalidates iterator. inline void reset() NOEXCEPT; /// True if the iterator is not terminal. @@ -81,7 +81,7 @@ class iterator /// Increment operators. inline self& operator++() NOEXCEPT; - inline self operator++(int) NOEXCEPT; + ////inline self operator++(int) NOEXCEPT; protected: Link to_first(Link link) const NOEXCEPT; @@ -94,7 +94,7 @@ class iterator // This is not thread safe, but it's object is not modified here and the // memory that it refers to is not addressable until written, and writes // are guarded by allocator, which is protected by mutex. - memory_ptr memory_; + memory memory_; // This is thread safe. const Key key_; diff --git a/include/bitcoin/database/primitives/manager.hpp b/include/bitcoin/database/primitives/manager.hpp index 8dc11c154..65b42fdbf 100644 --- a/include/bitcoin/database/primitives/manager.hpp +++ b/include/bitcoin/database/primitives/manager.hpp @@ -44,15 +44,11 @@ class managers /// Return memory object for column full map (null only if oom or unloaded). template - inline memory_ptr get() const NOEXCEPT; - template inline memory get1() const NOEXCEPT; /// Return memory object for column record (null only if oom or unloaded). /// Pointer is constrained to starting write within logical allocation. template - inline memory_ptr get(const Link& link) const NOEXCEPT; - template inline memory get1(const Link& link) const NOEXCEPT; template inline memory::iterator get_raw1(const Link& link) const NOEXCEPT; diff --git a/include/bitcoin/database/primitives/nomap.hpp b/include/bitcoin/database/primitives/nomap.hpp index b88d1d2d2..24e4531b2 100644 --- a/include/bitcoin/database/primitives/nomap.hpp +++ b/include/bitcoin/database/primitives/nomap.hpp @@ -86,7 +86,7 @@ class nomap bool reserve(const Link& size) NOEXCEPT; /// Return ptr for batch processing, holds shared lock on storage remap. - memory_ptr get_memory() const NOEXCEPT; + memory get_memory() const NOEXCEPT; /// Errors. /// ----------------------------------------------------------------------- @@ -105,7 +105,7 @@ class nomap /// Get element at link using get_memory() ptr, false if deserialize error. template = true> - static bool get(const memory_ptr& ptr, const Link& link, + static bool get(const memory& ptr, const Link& link, Element& element) NOEXCEPT; /// Get element at link. @@ -120,10 +120,7 @@ class nomap template = true> bool put(const Link& link, const Element& element) NOEXCEPT; template = true> - bool put(const memory_ptr& ptr, const Element& element) NOEXCEPT; - - template = true> - bool put(memory&& ptr, const Element& element) NOEXCEPT; + bool put(const memory& ptr, const Element& element) NOEXCEPT; /// Put element and return link. template = true> diff --git a/test/memory/mmap.cpp b/test/memory/mmap.cpp index 875e1e4d4..7b668babd 100644 --- a/test/memory/mmap.cpp +++ b/test/memory/mmap.cpp @@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(mmap__load__shared__load_locked) map instance(file); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.get(instance.allocate(1)); + auto memory = instance.get1(instance.allocate(1)); BOOST_REQUIRE(memory); BOOST_REQUIRE_EQUAL(instance.load(), error::load_locked); @@ -470,7 +470,7 @@ BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_capacity) auto memory = instance.get_filled(offset, size, fill); BOOST_REQUIRE(memory); - const auto expected = std::next(instance.get()->data(), offset); + const auto expected = std::next(instance.get1().data(), offset); BOOST_REQUIRE(memory.data() == expected); constexpr auto capacity = offset + size + to_half(offset + size); @@ -567,7 +567,7 @@ BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_fill) BOOST_REQUIRE_EQUAL(instance.capacity(), capacity); BOOST_REQUIRE_EQUAL(capacity, 12u); - auto data = instance.get()->data(); + auto data = instance.get1().data(); ////BOOST_REQUIRE_EQUAL(data[ 0], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 1], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 2], 0x00_u8); // cannot assume mmap default fill @@ -604,7 +604,7 @@ BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_fill) data[19] = 'h'; // Get data again in case it has been remapped by get_filled(). - data = instance.get()->data(); + data = instance.get1().data(); ////BOOST_REQUIRE_EQUAL(data[ 0], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 1], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 2], 0x00_u8); // cannot assume mmap default fill @@ -652,7 +652,7 @@ BOOST_AUTO_TEST_CASE(mmap__get__unloaded__false) map instance(file); BOOST_REQUIRE(!instance.open()); - BOOST_REQUIRE(!instance.get()); + BOOST_REQUIRE(!instance.get1()); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } @@ -665,7 +665,7 @@ BOOST_AUTO_TEST_CASE(mmap__get__loaded__success) map instance(file); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.get(instance.allocate(1))); + BOOST_REQUIRE(instance.get1(instance.allocate(1))); BOOST_REQUIRE(!instance.unload()); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); @@ -681,9 +681,9 @@ BOOST_AUTO_TEST_CASE(mmap__get__size__expected) BOOST_REQUIRE(!instance.load()); constexpr auto expected = 42u; - auto ptr = instance.get(instance.allocate(expected)); - BOOST_CHECK_EQUAL(ptr->size(), expected); - BOOST_CHECK_EQUAL(*ptr->begin(), 0x00u); + auto ptr = instance.get1(instance.allocate(expected)); + BOOST_CHECK_EQUAL(ptr.size(), expected); + BOOST_CHECK_EQUAL(*ptr.begin(), 0x00u); BOOST_REQUIRE(instance.unload()); ptr.reset(); @@ -770,16 +770,16 @@ BOOST_AUTO_TEST_CASE(mmap__write__read__expected) BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.get(instance.allocate(sizeof(uint64_t))); + auto memory = instance.get1(instance.allocate(sizeof(uint64_t))); BOOST_REQUIRE(memory); - system::unsafe_to_little_endian(memory->begin(), expected); + system::unsafe_to_little_endian(memory.begin(), expected); memory.reset(); BOOST_REQUIRE(!instance.flush()); - memory = instance.get(); + memory = instance.get1(); BOOST_REQUIRE(memory); - BOOST_REQUIRE_EQUAL(system::unsafe_from_little_endian(memory->begin()), expected); + BOOST_REQUIRE_EQUAL(system::unsafe_from_little_endian(memory.begin()), expected); memory.reset(); BOOST_REQUIRE(!instance.unload()); @@ -796,7 +796,7 @@ BOOST_AUTO_TEST_CASE(mmap__unload__shared__unload_locked) BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.get(instance.allocate(1)); + auto memory = instance.get1(instance.allocate(1)); BOOST_REQUIRE(memory); BOOST_REQUIRE_EQUAL(instance.unload(), error::unload_locked); diff --git a/test/mocks/chunk_storage.hpp b/test/mocks/chunk_storage.hpp index bedb3382b..42d50f9ba 100644 --- a/test/mocks/chunk_storage.hpp +++ b/test/mocks/chunk_storage.hpp @@ -281,11 +281,6 @@ class chunk_storages return std::next(at(column).data(), offset); } - memory_ptr get(size_t offset=zero) const NOEXCEPT override - { - return std::make_shared(get1(offset)); - } - memory get1(size_t offset=zero) const NOEXCEPT override { return get_at1(zero, offset); diff --git a/test/primitives/arrayhead.cpp b/test/primitives/arrayhead.cpp index 4a29b33e5..b361e700e 100644 --- a/test/primitives/arrayhead.cpp +++ b/test/primitives/arrayhead.cpp @@ -37,17 +37,18 @@ static_assert(buckets == 20u); using link = linkage; using test_header = arrayhead; -class nullptr_storage - : public test::chunk_storages -{ -public: - using chunk_storages::chunk_storages; - - memory_ptr get(size_t size) const NOEXCEPT override - { - return is_zero(size) ? chunk_storages::get(size) : nullptr; - } -}; +// TODO: see hashhead. +////class nullptr_storage +//// : public test::chunk_storages +////{ +////public: +//// using chunk_storages::chunk_storages; +//// +//// memory get(size_t size) const NOEXCEPT override +//// { +//// return is_zero(size) ? chunk_storages::get1(size) : memory{}; +//// } +////}; BOOST_AUTO_TEST_CASE(arrayhead__create__size__expected) { diff --git a/test/primitives/hashhead.cpp b/test/primitives/hashhead.cpp index 80feba828..dc6ccbfcc 100644 --- a/test/primitives/hashhead.cpp +++ b/test/primitives/hashhead.cpp @@ -48,9 +48,9 @@ class nullptr_storage public: using chunk_storages::chunk_storages; - memory_ptr get(size_t size) const NOEXCEPT override + memory get1(size_t size) const NOEXCEPT override { - return is_zero(size) ? chunk_storages::get(size) : nullptr; + return is_zero(size) ? chunk_storages::get1(size) : memory{}; } }; diff --git a/test/primitives/iterator.cpp b/test/primitives/iterator.cpp index 10143f2dc..6d8cdcc59 100644 --- a/test/primitives/iterator.cpp +++ b/test/primitives/iterator.cpp @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(iterator__self__empty__terminal) constexpr auto start = link::terminal; constexpr key key0{}; test::chunk_storage file; - const slab_iterate iterator{ file.get(), start, key0 }; + const slab_iterate iterator{ file.get1(), start, key0 }; BOOST_REQUIRE(iterator.get().is_terminal()); BOOST_REQUIRE(!iterator); BOOST_REQUIRE_EQUAL(iterator.key(), key0); @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(iterator__self__overflow__terminal) 0x00, 0x00, 0x00, 0x00 }; test::chunk_storage file{ data }; - const slab_iterate iterator{ file.get(), start, key0 }; + const slab_iterate iterator{ file.get1(), start, key0 }; BOOST_REQUIRE(iterator->is_terminal()); BOOST_REQUIRE(!iterator); BOOST_REQUIRE_EQUAL(iterator.key(), key0); @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(iterator__advance__record__expected) 0xff, 0xcc, 0xcc, 0xee }; test::chunk_storage file{ data }; - record_iterate iterator{ file.get(), start, key2 }; + record_iterate iterator{ file.get1(), start, key2 }; BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(iterator.get(), 0x00u); BOOST_REQUIRE(++iterator); @@ -98,10 +98,10 @@ BOOST_AUTO_TEST_CASE(iterator__advance__slab__expected) 0xff, 0xcc, 0xcc, 0xee, 0xee }; test::chunk_storage file{ data }; - slab_iterate iterator{ file.get(), start, key2 }; + slab_iterate iterator{ file.get1(), start, key2 }; BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(iterator.get(), 0x00u); - BOOST_REQUIRE(iterator++); + BOOST_REQUIRE(++iterator); BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(iterator.get(), 0x03u); BOOST_REQUIRE(!iterator.advance()); @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(iterator__reset__always__sets_terminal_retains_key) 0xff, 0xcc, 0xcc, 0xee, 0xee }; test::chunk_storage file{ data }; - slab_iterate iterator{ file.get(), start, key2 }; + slab_iterate iterator{ file.get1(), start, key2 }; BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(*iterator, 0x00u); diff --git a/test/primitives/manager.cpp b/test/primitives/manager.cpp index b88b28e09..ee8f2583f 100644 --- a/test/primitives/manager.cpp +++ b/test/primitives/manager.cpp @@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(manager__get__terminal_slab__terminal) test::chunk_storage file(buffer); const manager, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); - BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); + BOOST_REQUIRE(!instance.get1(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } @@ -181,10 +181,10 @@ BOOST_AUTO_TEST_CASE(manager__get__slab__expected) test::chunk_storage file(buffer); const manager, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); - BOOST_REQUIRE_EQUAL(*instance.get(0)->begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get(1)->begin(), 0x01_u8); - BOOST_REQUIRE_EQUAL(*instance.get(2)->begin(), 0x02_u8); - BOOST_REQUIRE_EQUAL(*instance.get(9)->begin(), 0x09_u8); + BOOST_REQUIRE_EQUAL(*instance.get1(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get1(1).begin(), 0x01_u8); + BOOST_REQUIRE_EQUAL(*instance.get1(2).begin(), 0x02_u8); + BOOST_REQUIRE_EQUAL(*instance.get1(9).begin(), 0x09_u8); BOOST_REQUIRE(!instance.get_fault()); } @@ -321,8 +321,8 @@ BOOST_AUTO_TEST_CASE(manager__get__terminal_record__terminal) test::chunk_storage file(buffer); const manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), (body - 1 * element)); - BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); + BOOST_REQUIRE_EQUAL(instance.get1(1).size(), (body - 1 * element)); + BOOST_REQUIRE(!instance.get1(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } @@ -340,9 +340,9 @@ BOOST_AUTO_TEST_CASE(manager__get__record__expected) test::chunk_storage file(buffer); const manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), expected); - BOOST_REQUIRE_EQUAL(*instance.get(0)->begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get(1)->begin(), 0x06_u8); + BOOST_REQUIRE_EQUAL(instance.get1(1).size(), expected); + BOOST_REQUIRE_EQUAL(*instance.get1(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get1(1).begin(), 0x06_u8); BOOST_REQUIRE(!instance.get_fault()); } @@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(manager__get_capacity__terminal_record__terminal) test::chunk_storage file(buffer); const manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), expected); + BOOST_REQUIRE_EQUAL(instance.get1(1).size(), expected); BOOST_REQUIRE(!instance.get_capacity(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } @@ -374,7 +374,7 @@ BOOST_AUTO_TEST_CASE(manager__get_capacity__record__expected) test::chunk_storage file(buffer); manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), expected); + BOOST_REQUIRE_EQUAL(instance.get1(1).size(), expected); BOOST_REQUIRE_EQUAL(*instance.get_capacity(0).begin(), 0x00_u8); BOOST_REQUIRE_EQUAL(*instance.get_capacity(1).begin(), 0x06_u8); BOOST_REQUIRE(!instance.get_fault()); diff --git a/test/primitives/nohead.cpp b/test/primitives/nohead.cpp index 671f4e0a2..d1a5f5f37 100644 --- a/test/primitives/nohead.cpp +++ b/test/primitives/nohead.cpp @@ -37,17 +37,18 @@ static_assert(buckets == 0u); using link = linkage; using test_header = nohead; -class nullptr_storage - : public test::chunk_storages -{ -public: - using chunk_storages::chunk_storages; - - memory_ptr get(size_t size) const NOEXCEPT override - { - return is_zero(size) ? chunk_storages::get(size) : nullptr; - } -}; +// TODO: see hashhead. +////class nullptr_storage +//// : public test::chunk_storages +////{ +////public: +//// using chunk_storages::chunk_storages; +//// +//// memory get(size_t size) const NOEXCEPT override +//// { +//// return is_zero(size) ? chunk_storages::get1(size) : memory{}; +//// } +////}; BOOST_AUTO_TEST_CASE(nohead__create__size__expected) { From e8b8d3d97d0c25f1ae811c6b5f8f5f22ad29c41c Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 19:01:54 -0400 Subject: [PATCH 09/10] Renames: get1->get, get_at1->get_at, get_at_raw->get_raw_at. --- .../database/impl/memory/mmap_dispatch.ipp | 12 +++---- .../database/impl/memory/mmap_storage.ipp | 2 +- .../database/impl/primitives/arrayhead.ipp | 8 ++--- .../database/impl/primitives/arraymap.ipp | 4 +-- .../database/impl/primitives/hashhead.ipp | 6 ++-- .../database/impl/primitives/hashmap.ipp | 4 +-- .../database/impl/primitives/manager.ipp | 14 ++++---- .../database/impl/primitives/nohead.ipp | 6 ++-- .../database/impl/primitives/nomap.ipp | 4 +-- .../database/impl/primitives/nomaps.ipp | 2 +- .../database/memory/interfaces/storage.hpp | 6 ++-- include/bitcoin/database/memory/mmap.hpp | 6 ++-- .../bitcoin/database/primitives/manager.hpp | 4 +-- test/memory/mmap.cpp | 32 +++++++++---------- test/mocks/chunk_storage.hpp | 10 +++--- test/primitives/arrayhead.cpp | 2 +- test/primitives/hashhead.cpp | 4 +-- test/primitives/iterator.cpp | 10 +++--- test/primitives/manager.cpp | 24 +++++++------- test/primitives/nohead.cpp | 2 +- test/tables/optional/filter_bk.cpp | 16 +++++----- test/tables/optional/filter_tx.cpp | 12 +++---- 22 files changed, 95 insertions(+), 95 deletions(-) diff --git a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp index 887ba4022..e93f603bb 100644 --- a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp +++ b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp @@ -67,7 +67,7 @@ memory CLASS::get_filled(size_t offset, size_t size, logical_ = end; } - return get1(offset); + return get(offset); } TEMPLATE @@ -89,11 +89,11 @@ TEMPLATE memory::iterator CLASS::get_raw(size_t offset) const NOEXCEPT { // Pointer otherwise unguarded, not remap safe (use for fixed table heads). - return get_at_raw(zero, offset); + return get_raw_at(zero, offset); } TEMPLATE -memory::iterator CLASS::get_at_raw(size_t column, size_t offset) const NOEXCEPT +memory::iterator CLASS::get_raw_at(size_t column, size_t offset) const NOEXCEPT { // get_raw not used for variably-sized heads, so should always be bounded. BC_ASSERT(offset < (size() * widths.at(column))); @@ -103,13 +103,13 @@ memory::iterator CLASS::get_at_raw(size_t column, size_t offset) const NOEXCEPT } TEMPLATE -memory CLASS::get1(size_t offset) const NOEXCEPT +memory CLASS::get(size_t offset) const NOEXCEPT { - return get_at1(zero, offset); + return get_at(zero, offset); } TEMPLATE -memory CLASS::get_at1(size_t column, size_t offset) const NOEXCEPT +memory CLASS::get_at(size_t column, size_t offset) const NOEXCEPT { if (column >= columns) return {}; diff --git a/include/bitcoin/database/impl/memory/mmap_storage.ipp b/include/bitcoin/database/impl/memory/mmap_storage.ipp index 9a233292a..8ab5ee395 100644 --- a/include/bitcoin/database/impl/memory/mmap_storage.ipp +++ b/include/bitcoin/database/impl/memory/mmap_storage.ipp @@ -255,7 +255,7 @@ TEMPLATE code CLASS::dump(const std::filesystem::path& path) const NOEXCEPT { BC_ASSERT(is_one(columns)); - const auto ptr = get1(); + const auto ptr = get(); if (!ptr) return error::unloaded_file; diff --git a/include/bitcoin/database/impl/primitives/arrayhead.ipp b/include/bitcoin/database/impl/primitives/arrayhead.ipp index d079794a2..7596c830a 100644 --- a/include/bitcoin/database/impl/primitives/arrayhead.ipp +++ b/include/bitcoin/database/impl/primitives/arrayhead.ipp @@ -63,7 +63,7 @@ inline Link CLASS::index(size_t key) const NOEXCEPT TEMPLATE bool CLASS::clear() NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr) return false; @@ -98,7 +98,7 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE bool CLASS::get_body_count(Link& count) const NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr || Link::size > size()) return false; @@ -112,7 +112,7 @@ bool CLASS::get_body_count(Link& count) const NOEXCEPT TEMPLATE bool CLASS::set_body_count(const Link& count) NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr || Link::size > size()) return false; @@ -137,7 +137,7 @@ Link CLASS::at(size_t key) const NOEXCEPT if (position >= size()) return {}; - const auto ptr = file_.get1(position); + const auto ptr = file_.get(position); if (!ptr) return {}; diff --git a/include/bitcoin/database/impl/primitives/arraymap.ipp b/include/bitcoin/database/impl/primitives/arraymap.ipp index 548901a8a..47146e64e 100644 --- a/include/bitcoin/database/impl/primitives/arraymap.ipp +++ b/include/bitcoin/database/impl/primitives/arraymap.ipp @@ -174,7 +174,7 @@ TEMPLATE ELEMENT_CONSTRAINT inline bool CLASS::get(const Link& link, Element& element) const NOEXCEPT { - const auto ptr = body_.get1(link); + const auto ptr = body_.get(link); if (!ptr) return false; @@ -195,7 +195,7 @@ bool CLASS::put(size_t key, const Element& element) NOEXCEPT return false; const auto link = body_.allocate(element.count()); - const auto ptr = body_.get1(link); + const auto ptr = body_.get(link); if (!ptr) return false; diff --git a/include/bitcoin/database/impl/primitives/hashhead.ipp b/include/bitcoin/database/impl/primitives/hashhead.ipp index 924e99bee..b2fd79a9c 100644 --- a/include/bitcoin/database/impl/primitives/hashhead.ipp +++ b/include/bitcoin/database/impl/primitives/hashhead.ipp @@ -64,7 +64,7 @@ bool CLASS::create() NOEXCEPT if (start == storage::eof) return false; - const auto ptr = file_.get1(start); + const auto ptr = file_.get(start); if (!ptr) return false; @@ -85,7 +85,7 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE bool CLASS::get_body_count(Link& count) const NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr) return false; @@ -99,7 +99,7 @@ bool CLASS::get_body_count(Link& count) const NOEXCEPT TEMPLATE bool CLASS::set_body_count(const Link& count) NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr) return false; diff --git a/include/bitcoin/database/impl/primitives/hashmap.ipp b/include/bitcoin/database/impl/primitives/hashmap.ipp index 3435d2067..ab8436469 100644 --- a/include/bitcoin/database/impl/primitives/hashmap.ipp +++ b/include/bitcoin/database/impl/primitives/hashmap.ipp @@ -210,14 +210,14 @@ inline Link CLASS::allocate(const Link& size) NOEXCEPT TEMPLATE inline memory CLASS::get_memory() const NOEXCEPT { - return body_.get1(); + return body_.get(); } TEMPLATE Key CLASS::get_key(const Link& link) NOEXCEPT { using namespace system; - const auto ptr = body_.get1(link); + const auto ptr = body_.get(link); if (!ptr || is_lesser(ptr.size(), index_size)) return {}; diff --git a/include/bitcoin/database/impl/primitives/manager.ipp b/include/bitcoin/database/impl/primitives/manager.ipp index 3f4663328..7baf7f22f 100644 --- a/include/bitcoin/database/impl/primitives/manager.ipp +++ b/include/bitcoin/database/impl/primitives/manager.ipp @@ -26,17 +26,17 @@ namespace database { TEMPLATE template -inline memory CLASS::get1() const NOEXCEPT +inline memory CLASS::get() const NOEXCEPT { if constexpr (is_one(columns)) - return files_.get1(); + return files_.get(); else - return files_.get_at1(Column); + return files_.get_at(Column); } TEMPLATE template -inline memory CLASS::get1(const Link& link) const NOEXCEPT +inline memory CLASS::get(const Link& link) const NOEXCEPT { if (link.is_terminal()) return {}; @@ -45,9 +45,9 @@ inline memory CLASS::get1(const Link& link) const NOEXCEPT // memory.size() may be negative (stream treats as exhausted). if constexpr (is_one(columns)) - return files_.get1(position); + return files_.get(position); else - return files_.get_at1(Column, position); + return files_.get_at(Column, position); } TEMPLATE @@ -63,7 +63,7 @@ inline memory::iterator CLASS::get_raw1(const Link& link) const NOEXCEPT if constexpr (is_one(columns)) return files_.get_raw(position); else - return files_.get_at_raw(Column, position); + return files_.get_raw_at(Column, position); } TEMPLATE diff --git a/include/bitcoin/database/impl/primitives/nohead.ipp b/include/bitcoin/database/impl/primitives/nohead.ipp index adfa31427..e9f76ed8e 100644 --- a/include/bitcoin/database/impl/primitives/nohead.ipp +++ b/include/bitcoin/database/impl/primitives/nohead.ipp @@ -55,7 +55,7 @@ bool CLASS::enabled() const NOEXCEPT TEMPLATE bool CLASS::clear() NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr) return false; @@ -90,7 +90,7 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE bool CLASS::get_body_count(Link& count) const NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr || Link::size > size()) return false; @@ -104,7 +104,7 @@ bool CLASS::get_body_count(Link& count) const NOEXCEPT TEMPLATE bool CLASS::set_body_count(const Link& count) NOEXCEPT { - const auto ptr = file_.get1(); + const auto ptr = file_.get(); if (!ptr || Link::size > size()) return false; diff --git a/include/bitcoin/database/impl/primitives/nomap.ipp b/include/bitcoin/database/impl/primitives/nomap.ipp index 832012a4a..d3dd8f7fc 100644 --- a/include/bitcoin/database/impl/primitives/nomap.ipp +++ b/include/bitcoin/database/impl/primitives/nomap.ipp @@ -130,7 +130,7 @@ bool CLASS::reserve(const Link& size) NOEXCEPT TEMPLATE memory CLASS::get_memory() const NOEXCEPT { - return manager_.get1(); + return manager_.get(); } // error condition @@ -210,7 +210,7 @@ template > bool CLASS::put(const Link& link, const Element& element) NOEXCEPT { using namespace system; - const auto ptr = manager_.get1(link); + const auto ptr = manager_.get(link); return put(ptr, element); } diff --git a/include/bitcoin/database/impl/primitives/nomaps.ipp b/include/bitcoin/database/impl/primitives/nomaps.ipp index 8e3b2257d..0b4d9fdc1 100644 --- a/include/bitcoin/database/impl/primitives/nomaps.ipp +++ b/include/bitcoin/database/impl/primitives/nomaps.ipp @@ -138,7 +138,7 @@ TEMPLATE template memory CLASS::get_memory() const NOEXCEPT { - return manager_.template get1(); + return manager_.template get(); } // static diff --git a/include/bitcoin/database/memory/interfaces/storage.hpp b/include/bitcoin/database/memory/interfaces/storage.hpp index 677078bdc..8ee755640 100644 --- a/include/bitcoin/database/memory/interfaces/storage.hpp +++ b/include/bitcoin/database/memory/interfaces/storage.hpp @@ -102,16 +102,16 @@ class storage /// Get unprotected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within full capacity. - virtual memory::iterator get_at_raw(size_t column, + virtual memory::iterator get_raw_at(size_t column, size_t offset=zero) const NOEXCEPT = 0; /// Get remap-protected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within logical allocation. - virtual memory get1(size_t offset=zero) const NOEXCEPT = 0; + virtual memory get(size_t offset=zero) const NOEXCEPT = 0; /// Same as get() but within specified column (or null for invalid column). /// Pointer is constrained to starting write within logical allocation. - virtual memory get_at1(size_t column, + virtual memory get_at(size_t column, size_t offset=zero) const NOEXCEPT = 0; }; diff --git a/include/bitcoin/database/memory/mmap.hpp b/include/bitcoin/database/memory/mmap.hpp index f0cabfc08..b4514c087 100644 --- a/include/bitcoin/database/memory/mmap.hpp +++ b/include/bitcoin/database/memory/mmap.hpp @@ -142,14 +142,14 @@ class mmap memory::iterator get_raw(size_t offset=zero) const NOEXCEPT override; /// Unprotected r/w access to start/offset (or null), within logical. - memory::iterator get_at_raw(size_t column, + memory::iterator get_raw_at(size_t column, size_t offset=zero) const NOEXCEPT override; /// Remap-protected r/w access to start/offset (or null), within logical. - memory get1(size_t offset=zero) const NOEXCEPT override; + memory get(size_t offset=zero) const NOEXCEPT override; /// Same as get() but within specified column (or null for invalid column). - memory get_at1(size_t column, size_t offset=zero) const NOEXCEPT override; + memory get_at(size_t column, size_t offset=zero) const NOEXCEPT override; protected: template diff --git a/include/bitcoin/database/primitives/manager.hpp b/include/bitcoin/database/primitives/manager.hpp index 65b42fdbf..f1a7c956b 100644 --- a/include/bitcoin/database/primitives/manager.hpp +++ b/include/bitcoin/database/primitives/manager.hpp @@ -44,12 +44,12 @@ class managers /// Return memory object for column full map (null only if oom or unloaded). template - inline memory get1() const NOEXCEPT; + inline memory get() const NOEXCEPT; /// Return memory object for column record (null only if oom or unloaded). /// Pointer is constrained to starting write within logical allocation. template - inline memory get1(const Link& link) const NOEXCEPT; + inline memory get(const Link& link) const NOEXCEPT; template inline memory::iterator get_raw1(const Link& link) const NOEXCEPT; diff --git a/test/memory/mmap.cpp b/test/memory/mmap.cpp index 7b668babd..f5838dac6 100644 --- a/test/memory/mmap.cpp +++ b/test/memory/mmap.cpp @@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(mmap__load__shared__load_locked) map instance(file); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.get1(instance.allocate(1)); + auto memory = instance.get(instance.allocate(1)); BOOST_REQUIRE(memory); BOOST_REQUIRE_EQUAL(instance.load(), error::load_locked); @@ -470,7 +470,7 @@ BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_capacity) auto memory = instance.get_filled(offset, size, fill); BOOST_REQUIRE(memory); - const auto expected = std::next(instance.get1().data(), offset); + const auto expected = std::next(instance.get().data(), offset); BOOST_REQUIRE(memory.data() == expected); constexpr auto capacity = offset + size + to_half(offset + size); @@ -567,7 +567,7 @@ BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_fill) BOOST_REQUIRE_EQUAL(instance.capacity(), capacity); BOOST_REQUIRE_EQUAL(capacity, 12u); - auto data = instance.get1().data(); + auto data = instance.get().data(); ////BOOST_REQUIRE_EQUAL(data[ 0], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 1], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 2], 0x00_u8); // cannot assume mmap default fill @@ -604,7 +604,7 @@ BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_fill) data[19] = 'h'; // Get data again in case it has been remapped by get_filled(). - data = instance.get1().data(); + data = instance.get().data(); ////BOOST_REQUIRE_EQUAL(data[ 0], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 1], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 2], 0x00_u8); // cannot assume mmap default fill @@ -652,7 +652,7 @@ BOOST_AUTO_TEST_CASE(mmap__get__unloaded__false) map instance(file); BOOST_REQUIRE(!instance.open()); - BOOST_REQUIRE(!instance.get1()); + BOOST_REQUIRE(!instance.get()); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } @@ -665,7 +665,7 @@ BOOST_AUTO_TEST_CASE(mmap__get__loaded__success) map instance(file); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.get1(instance.allocate(1))); + BOOST_REQUIRE(instance.get(instance.allocate(1))); BOOST_REQUIRE(!instance.unload()); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); @@ -681,7 +681,7 @@ BOOST_AUTO_TEST_CASE(mmap__get__size__expected) BOOST_REQUIRE(!instance.load()); constexpr auto expected = 42u; - auto ptr = instance.get1(instance.allocate(expected)); + auto ptr = instance.get(instance.allocate(expected)); BOOST_CHECK_EQUAL(ptr.size(), expected); BOOST_CHECK_EQUAL(*ptr.begin(), 0x00u); BOOST_REQUIRE(instance.unload()); @@ -770,14 +770,14 @@ BOOST_AUTO_TEST_CASE(mmap__write__read__expected) BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.get1(instance.allocate(sizeof(uint64_t))); + auto memory = instance.get(instance.allocate(sizeof(uint64_t))); BOOST_REQUIRE(memory); system::unsafe_to_little_endian(memory.begin(), expected); memory.reset(); BOOST_REQUIRE(!instance.flush()); - memory = instance.get1(); + memory = instance.get(); BOOST_REQUIRE(memory); BOOST_REQUIRE_EQUAL(system::unsafe_from_little_endian(memory.begin()), expected); @@ -796,7 +796,7 @@ BOOST_AUTO_TEST_CASE(mmap__unload__shared__unload_locked) BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.get1(instance.allocate(1)); + auto memory = instance.get(instance.allocate(1)); BOOST_REQUIRE(memory); BOOST_REQUIRE_EQUAL(instance.unload(), error::unload_locked); @@ -826,8 +826,8 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) // Row zero, written before remap (verifies preservation across remap). BOOST_REQUIRE_EQUAL(instance.allocate(1), zero); - auto write0_column0 = instance.get_at1(0, 0); - auto write0_column1 = instance.get_at1(1, 0); + auto write0_column0 = instance.get_at(0, 0); + auto write0_column1 = instance.get_at(1, 0); BOOST_REQUIRE(write0_column0); BOOST_REQUIRE(write0_column1); @@ -849,8 +849,8 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) BOOST_REQUIRE_EQUAL(std::filesystem::file_size(files.back()), rows * 3u); // Last row, through the remapped pointers. - auto write1_column0 = instance.get_at1(0, last * 1); - auto write1_column1 = instance.get_at1(1, last * 3); + auto write1_column0 = instance.get_at(0, last * 1); + auto write1_column1 = instance.get_at(1, last * 3); BOOST_REQUIRE(write1_column0); BOOST_REQUIRE(write1_column1); @@ -870,8 +870,8 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) BOOST_REQUIRE(!instance.load()); BOOST_REQUIRE_EQUAL(instance.size(), rows); - auto read_column0 = instance.get_at1(0, 0); - auto read_column1 = instance.get_at1(1, 0); + auto read_column0 = instance.get_at(0, 0); + auto read_column1 = instance.get_at(1, 0); BOOST_REQUIRE(read_column0); BOOST_REQUIRE(read_column1); BOOST_REQUIRE_EQUAL(read_column0.begin()[0], 'a'); diff --git a/test/mocks/chunk_storage.hpp b/test/mocks/chunk_storage.hpp index 42d50f9ba..3fd6d2b64 100644 --- a/test/mocks/chunk_storage.hpp +++ b/test/mocks/chunk_storage.hpp @@ -259,7 +259,7 @@ class chunk_storages logical_ = (minimum / widths[0]); } - return get1(offset); + return get(offset); } memory get_capacity(size_t offset=zero) const NOEXCEPT override @@ -275,18 +275,18 @@ class chunk_storages return std::next(at(zero).data(), offset); } - memory::iterator get_at_raw(size_t column, + memory::iterator get_raw_at(size_t column, size_t offset=zero) const NOEXCEPT override { return std::next(at(column).data(), offset); } - memory get1(size_t offset=zero) const NOEXCEPT override + memory get(size_t offset=zero) const NOEXCEPT override { - return get_at1(zero, offset); + return get_at(zero, offset); } - memory get_at1(size_t column, size_t offset=zero) const NOEXCEPT override + memory get_at(size_t column, size_t offset=zero) const NOEXCEPT override { using namespace system; auto data = at(column).data(); diff --git a/test/primitives/arrayhead.cpp b/test/primitives/arrayhead.cpp index b361e700e..1b730b365 100644 --- a/test/primitives/arrayhead.cpp +++ b/test/primitives/arrayhead.cpp @@ -46,7 +46,7 @@ using test_header = arrayhead; //// //// memory get(size_t size) const NOEXCEPT override //// { -//// return is_zero(size) ? chunk_storages::get1(size) : memory{}; +//// return is_zero(size) ? chunk_storages::get(size) : memory{}; //// } ////}; diff --git a/test/primitives/hashhead.cpp b/test/primitives/hashhead.cpp index dc6ccbfcc..f147405b2 100644 --- a/test/primitives/hashhead.cpp +++ b/test/primitives/hashhead.cpp @@ -48,9 +48,9 @@ class nullptr_storage public: using chunk_storages::chunk_storages; - memory get1(size_t size) const NOEXCEPT override + memory get(size_t size) const NOEXCEPT override { - return is_zero(size) ? chunk_storages::get1(size) : memory{}; + return is_zero(size) ? chunk_storages::get(size) : memory{}; } }; diff --git a/test/primitives/iterator.cpp b/test/primitives/iterator.cpp index 6d8cdcc59..3752d9b88 100644 --- a/test/primitives/iterator.cpp +++ b/test/primitives/iterator.cpp @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(iterator__self__empty__terminal) constexpr auto start = link::terminal; constexpr key key0{}; test::chunk_storage file; - const slab_iterate iterator{ file.get1(), start, key0 }; + const slab_iterate iterator{ file.get(), start, key0 }; BOOST_REQUIRE(iterator.get().is_terminal()); BOOST_REQUIRE(!iterator); BOOST_REQUIRE_EQUAL(iterator.key(), key0); @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(iterator__self__overflow__terminal) 0x00, 0x00, 0x00, 0x00 }; test::chunk_storage file{ data }; - const slab_iterate iterator{ file.get1(), start, key0 }; + const slab_iterate iterator{ file.get(), start, key0 }; BOOST_REQUIRE(iterator->is_terminal()); BOOST_REQUIRE(!iterator); BOOST_REQUIRE_EQUAL(iterator.key(), key0); @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(iterator__advance__record__expected) 0xff, 0xcc, 0xcc, 0xee }; test::chunk_storage file{ data }; - record_iterate iterator{ file.get1(), start, key2 }; + record_iterate iterator{ file.get(), start, key2 }; BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(iterator.get(), 0x00u); BOOST_REQUIRE(++iterator); @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(iterator__advance__slab__expected) 0xff, 0xcc, 0xcc, 0xee, 0xee }; test::chunk_storage file{ data }; - slab_iterate iterator{ file.get1(), start, key2 }; + slab_iterate iterator{ file.get(), start, key2 }; BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(iterator.get(), 0x00u); BOOST_REQUIRE(++iterator); @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(iterator__reset__always__sets_terminal_retains_key) 0xff, 0xcc, 0xcc, 0xee, 0xee }; test::chunk_storage file{ data }; - slab_iterate iterator{ file.get1(), start, key2 }; + slab_iterate iterator{ file.get(), start, key2 }; BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(*iterator, 0x00u); diff --git a/test/primitives/manager.cpp b/test/primitives/manager.cpp index ee8f2583f..4f0a35d8a 100644 --- a/test/primitives/manager.cpp +++ b/test/primitives/manager.cpp @@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(manager__get__terminal_slab__terminal) test::chunk_storage file(buffer); const manager, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); - BOOST_REQUIRE(!instance.get1(linkage<2>::terminal)); + BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } @@ -181,10 +181,10 @@ BOOST_AUTO_TEST_CASE(manager__get__slab__expected) test::chunk_storage file(buffer); const manager, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); - BOOST_REQUIRE_EQUAL(*instance.get1(0).begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get1(1).begin(), 0x01_u8); - BOOST_REQUIRE_EQUAL(*instance.get1(2).begin(), 0x02_u8); - BOOST_REQUIRE_EQUAL(*instance.get1(9).begin(), 0x09_u8); + BOOST_REQUIRE_EQUAL(*instance.get(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get(1).begin(), 0x01_u8); + BOOST_REQUIRE_EQUAL(*instance.get(2).begin(), 0x02_u8); + BOOST_REQUIRE_EQUAL(*instance.get(9).begin(), 0x09_u8); BOOST_REQUIRE(!instance.get_fault()); } @@ -321,8 +321,8 @@ BOOST_AUTO_TEST_CASE(manager__get__terminal_record__terminal) test::chunk_storage file(buffer); const manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get1(1).size(), (body - 1 * element)); - BOOST_REQUIRE(!instance.get1(linkage<2>::terminal)); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), (body - 1 * element)); + BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } @@ -340,9 +340,9 @@ BOOST_AUTO_TEST_CASE(manager__get__record__expected) test::chunk_storage file(buffer); const manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get1(1).size(), expected); - BOOST_REQUIRE_EQUAL(*instance.get1(0).begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get1(1).begin(), 0x06_u8); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); + BOOST_REQUIRE_EQUAL(*instance.get(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get(1).begin(), 0x06_u8); BOOST_REQUIRE(!instance.get_fault()); } @@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(manager__get_capacity__terminal_record__terminal) test::chunk_storage file(buffer); const manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get1(1).size(), expected); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); BOOST_REQUIRE(!instance.get_capacity(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } @@ -374,7 +374,7 @@ BOOST_AUTO_TEST_CASE(manager__get_capacity__record__expected) test::chunk_storage file(buffer); manager, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get1(1).size(), expected); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); BOOST_REQUIRE_EQUAL(*instance.get_capacity(0).begin(), 0x00_u8); BOOST_REQUIRE_EQUAL(*instance.get_capacity(1).begin(), 0x06_u8); BOOST_REQUIRE(!instance.get_fault()); diff --git a/test/primitives/nohead.cpp b/test/primitives/nohead.cpp index d1a5f5f37..da35b3958 100644 --- a/test/primitives/nohead.cpp +++ b/test/primitives/nohead.cpp @@ -46,7 +46,7 @@ using test_header = nohead; //// //// memory get(size_t size) const NOEXCEPT override //// { -//// return is_zero(size) ? chunk_storages::get1(size) : memory{}; +//// return is_zero(size) ? chunk_storages::get(size) : memory{}; //// } ////}; diff --git a/test/tables/optional/filter_bk.cpp b/test/tables/optional/filter_bk.cpp index 01b2a4649..8bbb0ffbc 100644 --- a/test/tables/optional/filter_bk.cpp +++ b/test/tables/optional/filter_bk.cpp @@ -91,24 +91,24 @@ BOOST_AUTO_TEST_CASE(filter_bk__put__ordered__expected) // Logical order is unaffected by put order. table::filter_bk::get_head get0{}; - table::filter_bk::get_head get1{}; + table::filter_bk::get_head get{}; table::filter_bk::get_head get2{}; table::filter_bk::get_head get3{}; table::filter_bk::get_head get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.hash, null_hash); - BOOST_REQUIRE_EQUAL(get1.hash, one_hash); + BOOST_REQUIRE_EQUAL(get.hash, one_hash); BOOST_REQUIRE_EQUAL(get2.hash, two_hash); BOOST_REQUIRE_EQUAL(get3.hash, three_hash); BOOST_REQUIRE_EQUAL(get4.hash, four_hash); BOOST_REQUIRE_EQUAL(get0.head, null_hash); - BOOST_REQUIRE_EQUAL(get1.head, five_hash); + BOOST_REQUIRE_EQUAL(get.head, five_hash); BOOST_REQUIRE_EQUAL(get2.head, six_hash); BOOST_REQUIRE_EQUAL(get3.head, seven_hash); BOOST_REQUIRE_EQUAL(get4.head, eight_hash); @@ -182,24 +182,24 @@ BOOST_AUTO_TEST_CASE(filter_bk__put__disordered__expected) // Logical order is unaffected by put order. table::filter_bk::get_head get0{}; - table::filter_bk::get_head get1{}; + table::filter_bk::get_head get{}; table::filter_bk::get_head get2{}; table::filter_bk::get_head get3{}; table::filter_bk::get_head get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.hash, null_hash); - BOOST_REQUIRE_EQUAL(get1.hash, one_hash); + BOOST_REQUIRE_EQUAL(get.hash, one_hash); BOOST_REQUIRE_EQUAL(get2.hash, two_hash); BOOST_REQUIRE_EQUAL(get3.hash, three_hash); BOOST_REQUIRE_EQUAL(get4.hash, four_hash); BOOST_REQUIRE_EQUAL(get0.head, null_hash); - BOOST_REQUIRE_EQUAL(get1.head, five_hash); + BOOST_REQUIRE_EQUAL(get.head, five_hash); BOOST_REQUIRE_EQUAL(get2.head, six_hash); BOOST_REQUIRE_EQUAL(get3.head, seven_hash); BOOST_REQUIRE_EQUAL(get4.head, eight_hash); diff --git a/test/tables/optional/filter_tx.cpp b/test/tables/optional/filter_tx.cpp index 71d033d1a..6b7ee11d3 100644 --- a/test/tables/optional/filter_tx.cpp +++ b/test/tables/optional/filter_tx.cpp @@ -89,17 +89,17 @@ BOOST_AUTO_TEST_CASE(filter_tx__put__ordered__expected) // Logical order is unaffected by put order. table::filter_tx::get_filter get0{}; - table::filter_tx::get_filter get1{}; + table::filter_tx::get_filter get{}; table::filter_tx::get_filter get2{}; table::filter_tx::get_filter get3{}; table::filter_tx::get_filter get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.filter, zero_data); - BOOST_REQUIRE_EQUAL(get1.filter, one_data); + BOOST_REQUIRE_EQUAL(get.filter, one_data); BOOST_REQUIRE_EQUAL(get2.filter, two_data); BOOST_REQUIRE_EQUAL(get3.filter, three_data); BOOST_REQUIRE_EQUAL(get4.filter, four_data); @@ -171,17 +171,17 @@ BOOST_AUTO_TEST_CASE(filter_tx__put__disordered__expected) // Logical order is unaffected by put order. table::filter_tx::get_filter get0{}; - table::filter_tx::get_filter get1{}; + table::filter_tx::get_filter get{}; table::filter_tx::get_filter get2{}; table::filter_tx::get_filter get3{}; table::filter_tx::get_filter get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.filter, zero_data); - BOOST_REQUIRE_EQUAL(get1.filter, one_data); + BOOST_REQUIRE_EQUAL(get.filter, one_data); BOOST_REQUIRE_EQUAL(get2.filter, two_data); BOOST_REQUIRE_EQUAL(get3.filter, three_data); BOOST_REQUIRE_EQUAL(get4.filter, four_data); From 4b9a5afec2827a3044b571536cf9c61392834baf Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 14 Jul 2026 19:37:03 -0400 Subject: [PATCH 10/10] Rename manager to body. --- builds/gnu/Makefile.am | 6 +- .../libbitcoin-database-test.vcxproj | 2 +- .../libbitcoin-database-test.vcxproj.filters | 6 +- .../libbitcoin-database.vcxproj | 4 +- .../libbitcoin-database.vcxproj.filters | 12 +- .../libbitcoin-database-test.vcxproj | 2 +- .../libbitcoin-database-test.vcxproj.filters | 6 +- .../libbitcoin-database.vcxproj | 4 +- .../libbitcoin-database.vcxproj.filters | 12 +- include/bitcoin/database.hpp | 2 +- .../database/impl/primitives/arrayhead.ipp | 2 +- .../impl/primitives/{manager.ipp => body.ipp} | 6 +- .../database/impl/primitives/iterator.ipp | 6 +- .../database/impl/primitives/nohead.ipp | 2 +- .../database/impl/primitives/nomap.ipp | 46 +++--- .../database/impl/primitives/nomaps.ipp | 32 ++-- .../bitcoin/database/primitives/arrayhead.hpp | 4 +- .../bitcoin/database/primitives/arraymap.hpp | 4 +- .../primitives/{manager.hpp => body.hpp} | 16 +- .../bitcoin/database/primitives/hashmap.hpp | 4 +- .../bitcoin/database/primitives/iterator.hpp | 8 +- .../bitcoin/database/primitives/nohead.hpp | 4 +- include/bitcoin/database/primitives/nomap.hpp | 6 +- .../bitcoin/database/primitives/nomaps.hpp | 6 +- .../database/primitives/primitives.hpp | 5 +- test/primitives/{manager.cpp => body.cpp} | 140 +++++++++--------- 26 files changed, 175 insertions(+), 172 deletions(-) rename include/bitcoin/database/impl/primitives/{manager.ipp => body.ipp} (98%) rename include/bitcoin/database/primitives/{manager.hpp => body.hpp} (93%) rename test/primitives/{manager.cpp => body.cpp} (69%) diff --git a/builds/gnu/Makefile.am b/builds/gnu/Makefile.am index 779dd0c99..ad966609e 100644 --- a/builds/gnu/Makefile.am +++ b/builds/gnu/Makefile.am @@ -102,12 +102,12 @@ include_bitcoin_database_impl_primitivesdir = \ include_bitcoin_database_impl_primitives_HEADERS = \ ${srcdir}/../../include/bitcoin/database/impl/primitives/arrayhead.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/arraymap.ipp \ + ${srcdir}/../../include/bitcoin/database/impl/primitives/body.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/hashhead.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/hashmap.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/iterator.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/keys.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/linkage.ipp \ - ${srcdir}/../../include/bitcoin/database/impl/primitives/manager.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/nohead.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/nomap.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/nomaps.ipp @@ -238,13 +238,13 @@ include_bitcoin_database_primitivesdir = \ include_bitcoin_database_primitives_HEADERS = \ ${srcdir}/../../include/bitcoin/database/primitives/arrayhead.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/arraymap.hpp \ + ${srcdir}/../../include/bitcoin/database/primitives/body.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/column.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/hashhead.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/hashmap.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/iterator.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/keys.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/linkage.hpp \ - ${srcdir}/../../include/bitcoin/database/primitives/manager.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/nohead.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/nomap.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/nomaps.hpp \ @@ -361,12 +361,12 @@ test_libbitcoin_database_test_SOURCES = \ ${srcdir}/../../test/mocks/blocks.cpp \ ${srcdir}/../../test/primitives/arrayhead.cpp \ ${srcdir}/../../test/primitives/arraymap.cpp \ + ${srcdir}/../../test/primitives/body.cpp \ ${srcdir}/../../test/primitives/hashhead.cpp \ ${srcdir}/../../test/primitives/hashmap.cpp \ ${srcdir}/../../test/primitives/iterator.cpp \ ${srcdir}/../../test/primitives/keys.cpp \ ${srcdir}/../../test/primitives/linkage.cpp \ - ${srcdir}/../../test/primitives/manager.cpp \ ${srcdir}/../../test/primitives/nohead.cpp \ ${srcdir}/../../test/primitives/nomap.cpp \ ${srcdir}/../../test/query/amounts.cpp \ diff --git a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj index 1fa17717a..a15e09cba 100644 --- a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj @@ -135,12 +135,12 @@ + - diff --git a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters index 7fa9e4d5d..df6a33f30 100644 --- a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters @@ -105,6 +105,9 @@ src\primitives + + src\primitives + src\primitives @@ -120,9 +123,6 @@ src\primitives - - src\primitives - src\primitives diff --git a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj index efedb59c9..31ff28add 100644 --- a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj @@ -163,13 +163,13 @@ + - @@ -227,12 +227,12 @@ + - diff --git a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters index 0d8fcc5f1..c5d038085 100644 --- a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters @@ -206,6 +206,9 @@ include\bitcoin\database\primitives + + include\bitcoin\database\primitives + include\bitcoin\database\primitives @@ -224,9 +227,6 @@ include\bitcoin\database\primitives - - include\bitcoin\database\primitives - include\bitcoin\database\primitives @@ -394,6 +394,9 @@ include\bitcoin\database\impl\primitives + + include\bitcoin\database\impl\primitives + include\bitcoin\database\impl\primitives @@ -409,9 +412,6 @@ include\bitcoin\database\impl\primitives - - include\bitcoin\database\impl\primitives - include\bitcoin\database\impl\primitives diff --git a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj index cdcacca69..a01439e5f 100644 --- a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj +++ b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj @@ -135,12 +135,12 @@ + - diff --git a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters index 7fa9e4d5d..df6a33f30 100644 --- a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters +++ b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters @@ -105,6 +105,9 @@ src\primitives + + src\primitives + src\primitives @@ -120,9 +123,6 @@ src\primitives - - src\primitives - src\primitives diff --git a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj index 3cba41c76..f3b32a16b 100644 --- a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj +++ b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj @@ -163,13 +163,13 @@ + - @@ -227,12 +227,12 @@ + - diff --git a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters index 0d8fcc5f1..c5d038085 100644 --- a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters +++ b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters @@ -206,6 +206,9 @@ include\bitcoin\database\primitives + + include\bitcoin\database\primitives + include\bitcoin\database\primitives @@ -224,9 +227,6 @@ include\bitcoin\database\primitives - - include\bitcoin\database\primitives - include\bitcoin\database\primitives @@ -394,6 +394,9 @@ include\bitcoin\database\impl\primitives + + include\bitcoin\database\impl\primitives + include\bitcoin\database\impl\primitives @@ -409,9 +412,6 @@ include\bitcoin\database\impl\primitives - - include\bitcoin\database\impl\primitives - include\bitcoin\database\impl\primitives diff --git a/include/bitcoin/database.hpp b/include/bitcoin/database.hpp index 2989b4496..36f8ae717 100644 --- a/include/bitcoin/database.hpp +++ b/include/bitcoin/database.hpp @@ -41,13 +41,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/include/bitcoin/database/impl/primitives/arrayhead.ipp b/include/bitcoin/database/impl/primitives/arrayhead.ipp index 7596c830a..57bad0353 100644 --- a/include/bitcoin/database/impl/primitives/arrayhead.ipp +++ b/include/bitcoin/database/impl/primitives/arrayhead.ipp @@ -81,7 +81,7 @@ bool CLASS::create() NOEXCEPT if (is_nonzero(size())) return false; - // Guards addition overflow in manager_.get (start must be valid). + // Guards addition overflow in body_.get (start must be valid). if (file_.allocate(link_to_position(initial_buckets_)) == storage::eof) return false; diff --git a/include/bitcoin/database/impl/primitives/manager.ipp b/include/bitcoin/database/impl/primitives/body.ipp similarity index 98% rename from include/bitcoin/database/impl/primitives/manager.ipp rename to include/bitcoin/database/impl/primitives/body.ipp index 7baf7f22f..49ccf64f8 100644 --- a/include/bitcoin/database/impl/primitives/manager.ipp +++ b/include/bitcoin/database/impl/primitives/body.ipp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP -#define LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP +#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_BODY_IPP +#define LIBBITCOIN_DATABASE_PRIMITIVES_BODY_IPP #include @@ -77,7 +77,7 @@ inline memory CLASS::get_capacity(const Link& link) const NOEXCEPT } TEMPLATE -CLASS::managers(storage& body) NOEXCEPT +CLASS::bodys(storage& body) NOEXCEPT : files_(body) { } diff --git a/include/bitcoin/database/impl/primitives/iterator.ipp b/include/bitcoin/database/impl/primitives/iterator.ipp index f7ec7695c..144c0f572 100644 --- a/include/bitcoin/database/impl/primitives/iterator.ipp +++ b/include/bitcoin/database/impl/primitives/iterator.ipp @@ -120,7 +120,7 @@ Link CLASS::to_first(Link link) const NOEXCEPT while (!link.is_terminal()) { // get element offset (fault) - const auto offset = memory_.offset(manager::link_to_position(link)); + const auto offset = memory_.offset(body::link_to_position(link)); if (is_null(offset)) return Link::terminal; @@ -142,7 +142,7 @@ Link CLASS::to_next(Link link) const NOEXCEPT while (!link.is_terminal()) { // get element offset (fault) - auto offset = memory_.offset(manager::link_to_position(link)); + auto offset = memory_.offset(body::link_to_position(link)); if (is_null(offset)) return Link::terminal; @@ -152,7 +152,7 @@ Link CLASS::to_next(Link link) const NOEXCEPT return link; // get next element offset (fault) - offset = memory_.offset(manager::link_to_position(link)); + offset = memory_.offset(body::link_to_position(link)); if (is_null(offset)) return Link::terminal; diff --git a/include/bitcoin/database/impl/primitives/nohead.ipp b/include/bitcoin/database/impl/primitives/nohead.ipp index e9f76ed8e..e907f7fc5 100644 --- a/include/bitcoin/database/impl/primitives/nohead.ipp +++ b/include/bitcoin/database/impl/primitives/nohead.ipp @@ -73,7 +73,7 @@ bool CLASS::create() NOEXCEPT if (is_nonzero(size())) return false; - // Guards addition overflow in manager_.get (start must be valid). + // Guards addition overflow in body_.get (start must be valid). if (file_.allocate(link_to_position(initial_buckets_)) == storage::eof) return false; diff --git a/include/bitcoin/database/impl/primitives/nomap.ipp b/include/bitcoin/database/impl/primitives/nomap.ipp index d3dd8f7fc..0f466bf08 100644 --- a/include/bitcoin/database/impl/primitives/nomap.ipp +++ b/include/bitcoin/database/impl/primitives/nomap.ipp @@ -26,7 +26,7 @@ namespace database { TEMPLATE CLASS::nomap(storage& header, storage& body) NOEXCEPT - : head_(header, 0), manager_(body) + : head_(header, 0), body_(body) { } @@ -38,19 +38,19 @@ bool CLASS::create() NOEXCEPT { Link count{}; return head_.create() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE bool CLASS::close() NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE bool CLASS::backup(bool) NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE @@ -58,7 +58,7 @@ bool CLASS::restore() NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE @@ -66,7 +66,7 @@ bool CLASS::verify() const NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && count == manager_.count(); + head_.get_body_count(count) && count == body_.count(); } // sizing @@ -87,50 +87,50 @@ size_t CLASS::head_size() const NOEXCEPT TEMPLATE size_t CLASS::body_size() const NOEXCEPT { - return manager_.size(); + return body_.size(); } TEMPLATE size_t CLASS::capacity() const NOEXCEPT { - return manager_.capacity(); + return body_.capacity(); } TEMPLATE Link CLASS::count() const NOEXCEPT { - return manager_.count(); + return body_.count(); } TEMPLATE bool CLASS::truncate(const Link& count) NOEXCEPT { - return manager_.truncate(count); + return body_.truncate(count); } TEMPLATE bool CLASS::expand(const Link& count) NOEXCEPT { - return manager_.expand(count); + return body_.expand(count); } TEMPLATE bool CLASS::drop() NOEXCEPT { - return manager_.truncate(0) && backup(); + return body_.truncate(0) && backup(); } TEMPLATE bool CLASS::reserve(const Link& size) NOEXCEPT { // Not writer-writer thread safe (two writers may share reserve). - return manager_.reserve(size); + return body_.reserve(size); } TEMPLATE memory CLASS::get_memory() const NOEXCEPT { - return manager_.get(); + return body_.get(); } // error condition @@ -139,19 +139,19 @@ memory CLASS::get_memory() const NOEXCEPT TEMPLATE code CLASS::get_fault() const NOEXCEPT { - return manager_.get_fault(); + return body_.get_fault(); } TEMPLATE size_t CLASS::get_space() const NOEXCEPT { - return manager_.get_space(); + return body_.get_space(); } TEMPLATE code CLASS::reload() NOEXCEPT { - return manager_.reload(); + return body_.reload(); } // query interface @@ -166,7 +166,7 @@ bool CLASS::get(const memory& ptr, const Link& link, Element& element) NOEXCEPT if (!ptr || link.is_terminal()) return false; - const auto start = manager::link_to_position(link); + const auto start = body::link_to_position(link); if (is_limited(start)) return false; @@ -210,7 +210,7 @@ template > bool CLASS::put(const Link& link, const Element& element) NOEXCEPT { using namespace system; - const auto ptr = manager_.get(link); + const auto ptr = body_.get(link); return put(ptr, element); } @@ -238,7 +238,7 @@ template > inline bool CLASS::put_link(Link& link, const Element& element) NOEXCEPT { const auto count = element.count(); - link = manager_.allocate(count); + link = body_.allocate(count); return put(link, element); } @@ -256,14 +256,14 @@ template > inline bool CLASS::commit(const Element& element) NOEXCEPT { // Zero allocation provides link of next (presumably reserved) element. - const auto link = manager_.allocate(0); + const auto link = body_.allocate(0); // Write element into reserved but unallocated space. - if (!put(manager_.get_capacity(link), element)) + if (!put(body_.get_capacity(link), element)) return false; // Allocate reserved and written element (exposes logically). - return !manager_.allocate(element.count()).is_terminal(); + return !body_.allocate(element.count()).is_terminal(); } } // namespace database diff --git a/include/bitcoin/database/impl/primitives/nomaps.ipp b/include/bitcoin/database/impl/primitives/nomaps.ipp index 0b4d9fdc1..4b9c8863b 100644 --- a/include/bitcoin/database/impl/primitives/nomaps.ipp +++ b/include/bitcoin/database/impl/primitives/nomaps.ipp @@ -28,7 +28,7 @@ namespace database { TEMPLATE CLASS::nomaps(storage& header, storage& body) NOEXCEPT : head_(header, 0), - manager_(body) + body_(body) { } @@ -40,19 +40,19 @@ bool CLASS::create() NOEXCEPT { Link count{}; return head_.create() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE bool CLASS::close() NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE bool CLASS::backup(bool) NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE @@ -60,7 +60,7 @@ bool CLASS::restore() NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE @@ -68,7 +68,7 @@ bool CLASS::verify() const NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && count == manager_.count(); + head_.get_body_count(count) && count == body_.count(); } // sizing @@ -77,31 +77,31 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE size_t CLASS::body_size() const NOEXCEPT { - return manager_.size(); + return body_.size(); } TEMPLATE Link CLASS::count() const NOEXCEPT { - return manager_.count(); + return body_.count(); } TEMPLATE Link CLASS::allocate(const Link& count) NOEXCEPT { - return manager_.allocate(count); + return body_.allocate(count); } TEMPLATE bool CLASS::truncate(const Link& count) NOEXCEPT { - return manager_.truncate(count); + return body_.truncate(count); } TEMPLATE bool CLASS::drop() NOEXCEPT { - return manager_.truncate(0) && backup(); + return body_.truncate(0) && backup(); } // Faults. @@ -110,19 +110,19 @@ bool CLASS::drop() NOEXCEPT TEMPLATE code CLASS::get_fault() const NOEXCEPT { - return manager_.get_fault(); + return body_.get_fault(); } TEMPLATE size_t CLASS::get_space() const NOEXCEPT { - return manager_.get_space(); + return body_.get_space(); } TEMPLATE code CLASS::reload() NOEXCEPT { - return manager_.reload(); + return body_.reload(); } // query interface @@ -138,7 +138,7 @@ TEMPLATE template memory CLASS::get_memory() const NOEXCEPT { - return manager_.template get(); + return body_.template get(); } // static @@ -184,7 +184,7 @@ TEMPLATE template bool CLASS::put(const Link& link, const Element& element) NOEXCEPT { - const auto ptr = manager_.template get_raw1(link); + const auto ptr = body_.template get_raw1(link); return put(ptr, element); } diff --git a/include/bitcoin/database/primitives/arrayhead.hpp b/include/bitcoin/database/primitives/arrayhead.hpp index 1e84a1af6..4af44a78a 100644 --- a/include/bitcoin/database/primitives/arrayhead.hpp +++ b/include/bitcoin/database/primitives/arrayhead.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { @@ -70,7 +70,7 @@ class arrayhead private: using link = Link::integer; - using body = manager, Link::size>; + using body = database::body, Link::size>; static_assert(std::atomic::is_always_lock_free); static_assert(is_nonzero(Link::size)); static constexpr auto bucket_size = Align ? sizeof(link) : Link::size; diff --git a/include/bitcoin/database/primitives/arraymap.hpp b/include/bitcoin/database/primitives/arraymap.hpp index e150ae880..78d19e643 100644 --- a/include/bitcoin/database/primitives/arraymap.hpp +++ b/include/bitcoin/database/primitives/arraymap.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { @@ -115,7 +115,7 @@ class arraymap private: static constexpr auto is_slab = (RowSize == max_size_t); using head = database::arrayhead; - using body = database::manager, RowSize>; + using body = database::body, RowSize>; // Thread safe (index/top/push). // Not thread safe (create/open/close/backup/restore). diff --git a/include/bitcoin/database/primitives/manager.hpp b/include/bitcoin/database/primitives/body.hpp similarity index 93% rename from include/bitcoin/database/primitives/manager.hpp rename to include/bitcoin/database/primitives/body.hpp index f1a7c956b..945c36408 100644 --- a/include/bitcoin/database/primitives/manager.hpp +++ b/include/bitcoin/database/primitives/body.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_HPP -#define LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_HPP +#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_BODY_HPP +#define LIBBITCOIN_DATABASE_PRIMITIVES_BODY_HPP #include #include @@ -28,7 +28,7 @@ namespace libbitcoin { namespace database { template -class managers +class bodys { public: using integer = typename Link::integer; @@ -40,7 +40,7 @@ class managers static constexpr integer cast_link(size_t link) NOEXCEPT; public: - DEFAULT_COPY_MOVE_DESTRUCT(managers); + DEFAULT_COPY_MOVE_DESTRUCT(bodys); /// Return memory object for column full map (null only if oom or unloaded). template @@ -58,7 +58,7 @@ class managers inline memory get_capacity(const Link& link) const NOEXCEPT; /// Manage shared multi-backed byte storage device (caller owns storage). - managers(storage& body) NOEXCEPT; + bodys(storage& body) NOEXCEPT; /// The aggregate logical byte size (cold size) across all columns. inline size_t size() const NOEXCEPT; @@ -117,15 +117,15 @@ class managers }; template -using manager = managers; +using body = bodys; } // namespace database } // namespace libbitcoin #define TEMPLATE template -#define CLASS managers +#define CLASS bodys -#include +#include #undef CLASS #undef TEMPLATE diff --git a/include/bitcoin/database/primitives/hashmap.hpp b/include/bitcoin/database/primitives/hashmap.hpp index 69dd41362..4413fac74 100644 --- a/include/bitcoin/database/primitives/hashmap.hpp +++ b/include/bitcoin/database/primitives/hashmap.hpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { @@ -229,7 +229,7 @@ class hashmap static constexpr auto key_size = keys::size(); static constexpr auto index_size = Link::size + key_size; using head = database::hashhead; - using body = database::manager; + using body = database::body; // Thread safe (index/top/push). // Not thread safe (create/open/close/backup/restore). diff --git a/include/bitcoin/database/primitives/iterator.hpp b/include/bitcoin/database/primitives/iterator.hpp index 44df7f4e2..744f993f2 100644 --- a/include/bitcoin/database/primitives/iterator.hpp +++ b/include/bitcoin/database/primitives/iterator.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { @@ -32,14 +32,14 @@ namespace database { /// OTHERWISE A DEADLOCK WILL OCCUR WHEN THE TABLE'S FILE IS EXPANDED, WHICH /// WAITS ON THE RELEASE OF THE SHARED LOCK (REMAP REQUIRES EXCLUSIVE ACCESS). /// THE hashmap.get(const iterator& it, ...) METHOD EXISTS TO PREVENT A CALL TO -/// manager.get(), WHICH DESPITE BEING A READ WOULD CAUSE A DEADLOCK. THIS IS +/// body.get(), WHICH DESPITE BEING A READ WOULD CAUSE A DEADLOCK. THIS IS /// BECAUSE IT CANNOT COMPLETE ITS READ WHILE REMAP IS WAITING ON ACCESS. /// A SIMILAR RISK ARISES FROM HOLDING iterator WHILE READING/WRITING ANY OTHER /// TABLE AS A CYCLE CAUSING THE ABOVE WILL OCCUR. USE THE ITERATOR TO COLLECT /// A SET FROM ITS TABLE AND THEN CALL iterator.release() TO FREE THE POINTER. /// This class is not thread safe. -/// Size non-max implies record manager (ordinal record links). +/// Size non-max implies record body (ordinal record links). template class iterator { @@ -88,7 +88,7 @@ class iterator Link to_next(Link link) const NOEXCEPT; private: - using manager = database::manager; + using body = database::body; static constexpr auto key_size = keys::size(); // This is not thread safe, but it's object is not modified here and the diff --git a/include/bitcoin/database/primitives/nohead.hpp b/include/bitcoin/database/primitives/nohead.hpp index da5a46bf8..1fdb6237d 100644 --- a/include/bitcoin/database/primitives/nohead.hpp +++ b/include/bitcoin/database/primitives/nohead.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include namespace libbitcoin { namespace database { @@ -60,7 +60,7 @@ class nohead private: using link = Link::integer; - using body = manager, Link::size>; + using body = database::body, Link::size>; static constexpr auto bucket_size = Link::size; static_assert(is_nonzero(bucket_size)); diff --git a/include/bitcoin/database/primitives/nomap.hpp b/include/bitcoin/database/primitives/nomap.hpp index 24e4531b2..0b20d34a3 100644 --- a/include/bitcoin/database/primitives/nomap.hpp +++ b/include/bitcoin/database/primitives/nomap.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include namespace libbitcoin { @@ -135,7 +135,7 @@ class nomap private: static constexpr auto is_slab = (Size == max_size_t); - using manager = database::manager, Size>; + using body = database::body, Size>; using head = database::nohead; // Thread safe (index/top/push). @@ -143,7 +143,7 @@ class nomap head head_; // Thread safe. - manager manager_; + body body_; }; template diff --git a/include/bitcoin/database/primitives/nomaps.hpp b/include/bitcoin/database/primitives/nomaps.hpp index f68b2b25f..cf825d522 100644 --- a/include/bitcoin/database/primitives/nomaps.hpp +++ b/include/bitcoin/database/primitives/nomaps.hpp @@ -25,7 +25,7 @@ namespace libbitcoin { namespace database { -/// SoA aggregate array table: one shared head + one unified managers body. +/// SoA aggregate array table: one shared head + one unified bodys body. template class nomaps { @@ -94,7 +94,7 @@ class nomaps protected: using head = database::nohead; - using body = database::managers, + using body = database::bodys, Columns::width...>; template @@ -105,7 +105,7 @@ class nomaps head head_; // This is thread safe. - body manager_; + body body_; }; } // namespace database diff --git a/include/bitcoin/database/primitives/primitives.hpp b/include/bitcoin/database/primitives/primitives.hpp index fbcb943cc..b0a61d2aa 100644 --- a/include/bitcoin/database/primitives/primitives.hpp +++ b/include/bitcoin/database/primitives/primitives.hpp @@ -19,17 +19,20 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_PRIMITIVES_HPP #define LIBBITCOIN_DATABASE_PRIMITIVES_PRIMITIVES_HPP +// helpers #include #include #include #include -#include // heads #include #include #include +// bodies +#include + // tables #include #include diff --git a/test/primitives/manager.cpp b/test/primitives/body.cpp similarity index 69% rename from test/primitives/manager.cpp rename to test/primitives/body.cpp index 4f0a35d8a..2ba99b9eb 100644 --- a/test/primitives/manager.cpp +++ b/test/primitives/body.cpp @@ -19,7 +19,7 @@ #include "../test.hpp" #include "../mocks/chunk_storage.hpp" -BOOST_AUTO_TEST_SUITE(manager_tests) +BOOST_AUTO_TEST_SUITE(body_tests) using namespace system; @@ -29,39 +29,39 @@ using key2 = system::data_array<2>; // slabs -BOOST_AUTO_TEST_CASE(manager__count__empty_slab__zero) +BOOST_AUTO_TEST_CASE(body__count__empty_slab__zero) { test::chunk_storage file; - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE(is_zero(instance.count())); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__count__non_empty_slab__expected) +BOOST_AUTO_TEST_CASE(body__count__non_empty_slab__expected) { constexpr auto expected = 42u; data_chunk buffer(expected, 0xff); test::chunk_storage file(buffer); // Slab sizing is byte-based (arbitrary, links are file offsets). - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__capacity__non_reserved__expected) +BOOST_AUTO_TEST_CASE(body__capacity__non_reserved__expected) { constexpr auto expected = 42u; data_chunk buffer(expected, 0xff); test::chunk_storage file(buffer); // Capacity is byte-based. - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.capacity(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__capacity__reserved__expected) +BOOST_AUTO_TEST_CASE(body__capacity__reserved__expected) { constexpr auto expand = 7u; constexpr auto initial = 42u; @@ -70,40 +70,40 @@ BOOST_AUTO_TEST_CASE(manager__capacity__reserved__expected) test::chunk_storage file(buffer); // Capacity is byte-based. - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(instance.reserve(expand)); BOOST_REQUIRE_EQUAL(instance.capacity(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__terminal_slab__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__terminal_slab__false_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(!instance.truncate(linkage<4>::terminal)); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__overflow_slab__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__overflow_slab__false_unchanged) { constexpr auto size = 42u; data_chunk buffer(size, 0xff); test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(!instance.truncate(add1(size))); BOOST_REQUIRE_EQUAL(instance.count(), size); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__half_full_slab__true_changed) +BOOST_AUTO_TEST_CASE(body__truncate__half_full_slab__true_changed) { constexpr auto size = 42u; constexpr auto half = to_half(size); data_chunk buffer(size, 0xff); test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(instance.truncate(half)); BOOST_REQUIRE_EQUAL(instance.count(), half); @@ -116,60 +116,60 @@ BOOST_AUTO_TEST_CASE(manager__truncate__half_full_slab__true_changed) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__eof_slab__terminal_unchanged) +BOOST_AUTO_TEST_CASE(body__allocate__eof_slab__terminal_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(storage::eof), linkage<7>::terminal); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__terminal_slab__terminal_unchanged) +BOOST_AUTO_TEST_CASE(body__allocate__terminal_slab__terminal_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(linkage<4>::terminal), linkage<4>::terminal); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__empty_slab__expected) +BOOST_AUTO_TEST_CASE(body__allocate__empty_slab__expected) { constexpr auto expected = 42u; data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(expected), zero); BOOST_REQUIRE_EQUAL(instance.count(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__non_empty_slab__expected) +BOOST_AUTO_TEST_CASE(body__allocate__non_empty_slab__expected) { constexpr auto expected = 42u; data_chunk buffer(to_half(expected), 0xff); test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(to_half(expected)), to_half(expected)); BOOST_REQUIRE_EQUAL(instance.count(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__terminal_slab__terminal) +BOOST_AUTO_TEST_CASE(body__get__terminal_slab__terminal) { constexpr auto size = 14u; data_chunk buffer(size, 0xff); test::chunk_storage file(buffer); - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__slab__expected) +BOOST_AUTO_TEST_CASE(body__get__slab__expected) { constexpr auto size = 16u; data_chunk buffer @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(manager__get__slab__expected) }; test::chunk_storage file(buffer); - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); BOOST_REQUIRE_EQUAL(*instance.get(0).begin(), 0x00_u8); BOOST_REQUIRE_EQUAL(*instance.get(1).begin(), 0x01_u8); @@ -190,15 +190,15 @@ BOOST_AUTO_TEST_CASE(manager__get__slab__expected) // records -BOOST_AUTO_TEST_CASE(manager__count__empty_record__zero) +BOOST_AUTO_TEST_CASE(body__count__empty_record__zero) { test::chunk_storage file; - const manager, key1, 42> instance(file); + const body, key1, 42> instance(file); BOOST_REQUIRE(is_zero(instance.count())); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__count__1_record__expected) +BOOST_AUTO_TEST_CASE(body__count__1_record__expected) { constexpr auto count = 1u; constexpr auto bytes = 5u; @@ -207,81 +207,81 @@ BOOST_AUTO_TEST_CASE(manager__count__1_record__expected) test::chunk_storage file(buffer); // Record sizing is record count-based (links are record counters). - const manager, key1, bytes> instance(file); + const body, key1, bytes> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__count__33_record__expected) +BOOST_AUTO_TEST_CASE(body__count__33_record__expected) { constexpr auto count = 33u; constexpr auto bytes = 5u; constexpr auto expected = count * (sizeof(uint32_t) + bytes + array_count); data_chunk buffer(expected, 0xff); test::chunk_storage file(buffer); - const manager, key2, bytes> instance(file); + const body, key2, bytes> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 33u); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__terminal_record__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__terminal_record__false_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE(!instance.truncate(linkage<2>::terminal)); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__overflow_record__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__overflow_record__false_unchanged) { data_chunk buffer(7, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE(!instance.truncate(2)); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__half_full_record__true_logical_size_changed) +BOOST_AUTO_TEST_CASE(body__truncate__half_full_record__true_logical_size_changed) { - constexpr auto body = 14u; - data_chunk buffer(body, 0xff); + constexpr auto bodie = 14u; + data_chunk buffer(bodie, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE(instance.truncate(1)); BOOST_REQUIRE_EQUAL(instance.count(), 1u); - BOOST_REQUIRE_EQUAL(instance.capacity(), body); + BOOST_REQUIRE_EQUAL(instance.capacity(), bodie); // Can only truncate to logical limit. BOOST_REQUIRE(!instance.truncate(2)); BOOST_REQUIRE_EQUAL(instance.count(), 1u); - BOOST_REQUIRE_EQUAL(instance.capacity(), body); + BOOST_REQUIRE_EQUAL(instance.capacity(), bodie); BOOST_REQUIRE(instance.truncate(0)); BOOST_REQUIRE_EQUAL(instance.count(), 0u); - BOOST_REQUIRE_EQUAL(instance.capacity(), body); + BOOST_REQUIRE_EQUAL(instance.capacity(), bodie); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__terminal_empty_record__terminal_unchanged) +BOOST_AUTO_TEST_CASE(body__allocate__terminal_empty_record__terminal_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(linkage<2>::terminal), linkage<2>::terminal); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__terminal_non_empty_record__expected) +BOOST_AUTO_TEST_CASE(body__allocate__terminal_non_empty_record__expected) { data_chunk buffer(7, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(1), 1u); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.allocate(linkage<2>::terminal), linkage<2>::terminal); @@ -289,11 +289,11 @@ BOOST_AUTO_TEST_CASE(manager__allocate__terminal_non_empty_record__expected) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__empty_record__expected) +BOOST_AUTO_TEST_CASE(body__allocate__empty_record__expected) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(1), 0u); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE_EQUAL(instance.allocate(2), 1u); @@ -301,11 +301,11 @@ BOOST_AUTO_TEST_CASE(manager__allocate__empty_record__expected) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__non_empty_record__expected) +BOOST_AUTO_TEST_CASE(body__allocate__non_empty_record__expected) { data_chunk buffer(7, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(1), 1u); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.allocate(2), 2u); @@ -313,20 +313,20 @@ BOOST_AUTO_TEST_CASE(manager__allocate__non_empty_record__expected) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__terminal_record__terminal) +BOOST_AUTO_TEST_CASE(body__get__terminal_record__terminal) { - constexpr auto body = 14u; + constexpr auto bodie = 14u; constexpr auto element = 5u; - data_chunk buffer(body, 0xff); + data_chunk buffer(bodie, 0xff); test::chunk_storage file(buffer); - const manager, key0, element> instance(file); + const body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1).size(), (body - 1 * element)); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), (bodie - 1 * element)); BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__record__expected) +BOOST_AUTO_TEST_CASE(body__get__record__expected) { data_chunk buffer { @@ -335,10 +335,10 @@ BOOST_AUTO_TEST_CASE(manager__get__record__expected) }; constexpr auto element = 6u; - const auto body = buffer.size(); - const auto expected = to_signed(body - 1u * element); + const auto bodie = buffer.size(); + const auto expected = to_signed(bodie - 1u * element); test::chunk_storage file(buffer); - const manager, key0, element> instance(file); + const body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); BOOST_REQUIRE_EQUAL(*instance.get(0).begin(), 0x00_u8); @@ -346,21 +346,21 @@ BOOST_AUTO_TEST_CASE(manager__get__record__expected) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get_capacity__terminal_record__terminal) +BOOST_AUTO_TEST_CASE(body__get_capacity__terminal_record__terminal) { - constexpr auto body = 14u; + constexpr auto bodie = 14u; constexpr auto element = 5u; - constexpr auto expected = to_signed(body - 1u * element); - data_chunk buffer(body, 0xff); + constexpr auto expected = to_signed(bodie - 1u * element); + data_chunk buffer(bodie, 0xff); test::chunk_storage file(buffer); - const manager, key0, element> instance(file); + const body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); BOOST_REQUIRE(!instance.get_capacity(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get_capacity__record__expected) +BOOST_AUTO_TEST_CASE(body__get_capacity__record__expected) { data_chunk buffer { @@ -369,10 +369,10 @@ BOOST_AUTO_TEST_CASE(manager__get_capacity__record__expected) }; constexpr auto element = 6u; - const auto body = buffer.size(); - const auto expected = to_signed(body - 1u * element); + const auto bodie = buffer.size(); + const auto expected = to_signed(bodie - 1u * element); test::chunk_storage file(buffer); - manager, key0, element> instance(file); + body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); BOOST_REQUIRE_EQUAL(*instance.get_capacity(0).begin(), 0x00_u8);