File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,8 +77,10 @@ bool CLASS::clear() NOEXCEPT
7777 if (!ptr)
7878 return false ;
7979
80- // std::memset/fill_n have identical performance (on win32).
81- // //std::memset(ptr->data(), system::bit_all<uint8_t>, size());
80+ // Retains head size, since head is array not map, and resets body logical
81+ // count to zero, which is picked up in arraymap::reset(). Body file size
82+ // remains unchanged and subject to initialization size at each startup. So
83+ // there is no reduction until restart, which can include config change.
8284 std::fill_n (ptr->data (), size (), system::bit_all<uint8_t >);
8385 return set_body_count (zero);
8486}
Original file line number Diff line number Diff line change @@ -49,6 +49,14 @@ bool CLASS::close() NOEXCEPT
4949 return head_.set_body_count (body_.count ());
5050}
5151
52+ TEMPLATE
53+ bool CLASS::reset () NOEXCEPT
54+ {
55+ Link count{};
56+ return head_.clear () && head_.get_body_count (count) &&
57+ body_.truncate (count);
58+ }
59+
5260TEMPLATE
5361bool CLASS::backup () NOEXCEPT
5462{
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ class arraymap
5050
5151 bool create () NOEXCEPT;
5252 bool close () NOEXCEPT;
53+ bool reset () NOEXCEPT;
5354 bool backup () NOEXCEPT;
5455 bool restore () NOEXCEPT;
5556 bool verify () const NOEXCEPT;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(arrayhead__get_body_count__created__zero)
8888 BOOST_REQUIRE_EQUAL (count, zero);
8989}
9090
91- BOOST_AUTO_TEST_CASE (arrayhead__set_body_count__get__expected )
91+ BOOST_AUTO_TEST_CASE (arrayhead__set_body_count__get_body_count__expected )
9292{
9393 data_chunk data;
9494 test::chunk_storage store{ data };
@@ -103,6 +103,25 @@ BOOST_AUTO_TEST_CASE(arrayhead__set_body_count__get__expected)
103103 BOOST_REQUIRE_EQUAL (count, expected);
104104}
105105
106+ BOOST_AUTO_TEST_CASE (arrayhead__clear__get_body_count__zero)
107+ {
108+ data_chunk data;
109+ test::chunk_storage store{ data };
110+ test_header head{ store, buckets };
111+ BOOST_REQUIRE (head.create ());
112+
113+ constexpr auto expected = 42u ;
114+ BOOST_REQUIRE (head.set_body_count (expected));
115+
116+ link count{};
117+ BOOST_REQUIRE (head.get_body_count (count));
118+ BOOST_REQUIRE_EQUAL (count, expected);
119+
120+ BOOST_REQUIRE (head.clear ());
121+ BOOST_REQUIRE (head.get_body_count (count));
122+ BOOST_REQUIRE_EQUAL (count, zero);
123+ }
124+
106125BOOST_AUTO_TEST_CASE (arrayhead__at__key__terminal)
107126{
108127 test::chunk_storage store;
Original file line number Diff line number Diff line change @@ -855,6 +855,19 @@ BOOST_AUTO_TEST_CASE(arraymap__record_body_count__nine_close__nine)
855855 BOOST_REQUIRE (!instance.get_fault ());
856856}
857857
858+ BOOST_AUTO_TEST_CASE (arraymap__reset__nine_close__zero)
859+ {
860+ test::chunk_storage head_store{};
861+ test::chunk_storage body_store{};
862+ record_table instance{ head_store, body_store, initial_buckets };
863+ BOOST_REQUIRE (instance.create ());
864+ body_store.buffer () = base16_chunk (" 112233441122334411223344112233441122334411223344112233441122334411223344" );
865+ BOOST_REQUIRE (instance.reset ());
866+ BOOST_REQUIRE (instance.close ());
867+ BOOST_REQUIRE_EQUAL (head_store.buffer (), base16_chunk (" 000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ));
868+ BOOST_REQUIRE (!instance.get_fault ());
869+ }
870+
858871BOOST_AUTO_TEST_CASE (arraymap__record_body_count__nine_backup__nine)
859872{
860873 test::chunk_storage head_store{};
You can’t perform that action at this time.
0 commit comments