Skip to content

Commit a5b6e4e

Browse files
committed
Rename head2 to arrayhead, allow empty files in validate().
1 parent 8f61a1f commit a5b6e4e

File tree

12 files changed

+45
-45
lines changed

12 files changed

+45
-45
lines changed

Makefile.am

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ test_libbitcoin_database_test_SOURCES = \
7676
test/mocks/chunk_storage.hpp \
7777
test/mocks/chunk_store.hpp \
7878
test/mocks/map_store.hpp \
79+
test/primitives/arrayhead.cpp \
7980
test/primitives/arraymap.cpp \
8081
test/primitives/hashmap.cpp \
8182
test/primitives/head.cpp \
82-
test/primitives/head2.cpp \
8383
test/primitives/iterator.cpp \
8484
test/primitives/linkage.cpp \
8585
test/primitives/manager.cpp \
@@ -159,10 +159,10 @@ include_bitcoin_database_impl_memory_HEADERS = \
159159

160160
include_bitcoin_database_impl_primitivesdir = ${includedir}/bitcoin/database/impl/primitives
161161
include_bitcoin_database_impl_primitives_HEADERS = \
162+
include/bitcoin/database/impl/primitives/arrayhead.ipp \
162163
include/bitcoin/database/impl/primitives/arraymap.ipp \
163164
include/bitcoin/database/impl/primitives/hashmap.ipp \
164165
include/bitcoin/database/impl/primitives/head.ipp \
165-
include/bitcoin/database/impl/primitives/head2.ipp \
166166
include/bitcoin/database/impl/primitives/iterator.ipp \
167167
include/bitcoin/database/impl/primitives/linkage.ipp \
168168
include/bitcoin/database/impl/primitives/manager.ipp \
@@ -206,10 +206,10 @@ include_bitcoin_database_memory_interfaces_HEADERS = \
206206

207207
include_bitcoin_database_primitivesdir = ${includedir}/bitcoin/database/primitives
208208
include_bitcoin_database_primitives_HEADERS = \
209+
include/bitcoin/database/primitives/arrayhead.hpp \
209210
include/bitcoin/database/primitives/arraymap.hpp \
210211
include/bitcoin/database/primitives/hashmap.hpp \
211212
include/bitcoin/database/primitives/head.hpp \
212-
include/bitcoin/database/primitives/head2.hpp \
213213
include/bitcoin/database/primitives/iterator.hpp \
214214
include/bitcoin/database/primitives/linkage.hpp \
215215
include/bitcoin/database/primitives/manager.hpp \

builds/cmake/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ if (with-tests)
284284
"../../test/mocks/chunk_storage.hpp"
285285
"../../test/mocks/chunk_store.hpp"
286286
"../../test/mocks/map_store.hpp"
287+
"../../test/primitives/arrayhead.cpp"
287288
"../../test/primitives/arraymap.cpp"
288289
"../../test/primitives/hashmap.cpp"
289290
"../../test/primitives/head.cpp"
290-
"../../test/primitives/head2.cpp"
291291
"../../test/primitives/iterator.cpp"
292292
"../../test/primitives/linkage.cpp"
293293
"../../test/primitives/manager.cpp"

builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
<ObjectFileName>$(IntDir)test_memory_utilities.obj</ObjectFileName>
8686
</ClCompile>
8787
<ClCompile Include="..\..\..\..\test\mocks\chunk_storage.cpp" />
88+
<ClCompile Include="..\..\..\..\test\primitives\arrayhead.cpp" />
8889
<ClCompile Include="..\..\..\..\test\primitives\arraymap.cpp" />
8990
<ClCompile Include="..\..\..\..\test\primitives\hashmap.cpp" />
9091
<ClCompile Include="..\..\..\..\test\primitives\head.cpp" />
91-
<ClCompile Include="..\..\..\..\test\primitives\head2.cpp" />
9292
<ClCompile Include="..\..\..\..\test\primitives\iterator.cpp" />
9393
<ClCompile Include="..\..\..\..\test\primitives\linkage.cpp" />
9494
<ClCompile Include="..\..\..\..\test\primitives\manager.cpp" />

builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<ClCompile Include="..\..\..\..\test\mocks\chunk_storage.cpp">
7979
<Filter>src\mocks</Filter>
8080
</ClCompile>
81+
<ClCompile Include="..\..\..\..\test\primitives\arrayhead.cpp">
82+
<Filter>src\primitives</Filter>
83+
</ClCompile>
8184
<ClCompile Include="..\..\..\..\test\primitives\arraymap.cpp">
8285
<Filter>src\primitives</Filter>
8386
</ClCompile>
@@ -87,9 +90,6 @@
8790
<ClCompile Include="..\..\..\..\test\primitives\head.cpp">
8891
<Filter>src\primitives</Filter>
8992
</ClCompile>
90-
<ClCompile Include="..\..\..\..\test\primitives\head2.cpp">
91-
<Filter>src\primitives</Filter>
92-
</ClCompile>
9393
<ClCompile Include="..\..\..\..\test\primitives\iterator.cpp">
9494
<Filter>src\primitives</Filter>
9595
</ClCompile>

builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@
113113
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\simple_writer.hpp" />
114114
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\streamers.hpp" />
115115
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\utilities.hpp" />
116+
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\arrayhead.hpp" />
116117
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\arraymap.hpp" />
117118
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\hashmap.hpp" />
118119
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\head.hpp" />
119-
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\head2.hpp" />
120120
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\iterator.hpp" />
121121
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\linkage.hpp" />
122122
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\manager.hpp" />
@@ -153,10 +153,10 @@
153153
<None Include="..\..\..\..\include\bitcoin\database\impl\memory\accessor.ipp" />
154154
<None Include="..\..\..\..\include\bitcoin\database\impl\memory\simple_reader.ipp" />
155155
<None Include="..\..\..\..\include\bitcoin\database\impl\memory\simple_writer.ipp" />
156+
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\arrayhead.ipp" />
156157
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\arraymap.ipp" />
157158
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\hashmap.ipp" />
158159
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\head.ipp" />
159-
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\head2.ipp" />
160160
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\iterator.ipp" />
161161
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\linkage.ipp" />
162162
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\manager.ipp" />

builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@
182182
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\utilities.hpp">
183183
<Filter>include\bitcoin\database\memory</Filter>
184184
</ClInclude>
185+
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\arrayhead.hpp">
186+
<Filter>include\bitcoin\database\primitives</Filter>
187+
</ClInclude>
185188
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\arraymap.hpp">
186189
<Filter>include\bitcoin\database\primitives</Filter>
187190
</ClInclude>
@@ -191,9 +194,6 @@
191194
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\head.hpp">
192195
<Filter>include\bitcoin\database\primitives</Filter>
193196
</ClInclude>
194-
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\head2.hpp">
195-
<Filter>include\bitcoin\database\primitives</Filter>
196-
</ClInclude>
197197
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\iterator.hpp">
198198
<Filter>include\bitcoin\database\primitives</Filter>
199199
</ClInclude>
@@ -298,6 +298,9 @@
298298
<None Include="..\..\..\..\include\bitcoin\database\impl\memory\simple_writer.ipp">
299299
<Filter>include\bitcoin\database\impl\memory</Filter>
300300
</None>
301+
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\arrayhead.ipp">
302+
<Filter>include\bitcoin\database\impl\primitives</Filter>
303+
</None>
301304
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\arraymap.ipp">
302305
<Filter>include\bitcoin\database\impl\primitives</Filter>
303306
</None>
@@ -307,9 +310,6 @@
307310
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\head.ipp">
308311
<Filter>include\bitcoin\database\impl\primitives</Filter>
309312
</None>
310-
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\head2.ipp">
311-
<Filter>include\bitcoin\database\impl\primitives</Filter>
312-
</None>
313313
<None Include="..\..\..\..\include\bitcoin\database\impl\primitives\iterator.ipp">
314314
<Filter>include\bitcoin\database\impl\primitives</Filter>
315315
</None>

include/bitcoin/database.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
#include <bitcoin/database/memory/utilities.hpp>
4343
#include <bitcoin/database/memory/interfaces/memory.hpp>
4444
#include <bitcoin/database/memory/interfaces/storage.hpp>
45+
#include <bitcoin/database/primitives/arrayhead.hpp>
4546
#include <bitcoin/database/primitives/arraymap.hpp>
4647
#include <bitcoin/database/primitives/hashmap.hpp>
4748
#include <bitcoin/database/primitives/head.hpp>
48-
#include <bitcoin/database/primitives/head2.hpp>
4949
#include <bitcoin/database/primitives/iterator.hpp>
5050
#include <bitcoin/database/primitives/linkage.hpp>
5151
#include <bitcoin/database/primitives/manager.hpp>

include/bitcoin/database/impl/primitives/head2.ipp renamed to include/bitcoin/database/impl/primitives/arrayhead.ipp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19-
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_HEAD2_IPP
20-
#define LIBBITCOIN_DATABASE_PRIMITIVES_HEAD2_IPP
19+
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYHEAD_IPP
20+
#define LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYHEAD_IPP
2121

2222
#include <algorithm>
2323
#include <bitcoin/system.hpp>
@@ -27,7 +27,7 @@ namespace libbitcoin {
2727
namespace database {
2828

2929
TEMPLATE
30-
CLASS::head2(storage& head, const Link& buckets) NOEXCEPT
30+
CLASS::arrayhead(storage& head, const Link& buckets) NOEXCEPT
3131
: file_(head), initial_buckets_(buckets)
3232
{
3333
}
@@ -98,7 +98,7 @@ TEMPLATE
9898
bool CLASS::get_body_count(Link& count) const NOEXCEPT
9999
{
100100
const auto ptr = file_.get();
101-
if (!ptr)
101+
if (!ptr || Link::size > file_.size())
102102
return false;
103103

104104
count = array_cast<Link::size>(ptr->data());
@@ -109,7 +109,7 @@ TEMPLATE
109109
bool CLASS::set_body_count(const Link& count) NOEXCEPT
110110
{
111111
const auto ptr = file_.get();
112-
if (!ptr)
112+
if (!ptr || Link::size > file_.size())
113113
return false;
114114

115115
array_cast<Link::size>(ptr->data()) = count;

include/bitcoin/database/primitives/head2.hpp renamed to include/bitcoin/database/primitives/arrayhead.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19-
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_HEAD2_HPP
20-
#define LIBBITCOIN_DATABASE_PRIMITIVES_HEAD2_HPP
19+
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYHEAD_HPP
20+
#define LIBBITCOIN_DATABASE_PRIMITIVES_ARRAYHEAD_HPP
2121

2222
#include <shared_mutex>
2323
#include <bitcoin/system.hpp>
@@ -30,15 +30,15 @@ namespace database {
3030
/// Dynamically expanding array map header.
3131
/// Less efficient than a fixed-size header.
3232
template <typename Link, typename Key = size_t>
33-
class head2
33+
class arrayhead
3434
{
3535
public:
36-
DEFAULT_COPY_MOVE_DESTRUCT(head2);
36+
DEFAULT_COPY_MOVE_DESTRUCT(arrayhead);
3737

3838
using bytes = typename Link::bytes;
3939

40-
/// An array head has zero buckets (and cannot call index()).
41-
head2(storage& head, const Link& buckets) NOEXCEPT;
40+
/// An array head is disabled it if has one or less buckets.
41+
arrayhead(storage& head, const Link& buckets) NOEXCEPT;
4242

4343
/// Sizing is dynamic (thread safe).
4444
size_t size() const NOEXCEPT;
@@ -99,9 +99,9 @@ class head2
9999
} // namespace libbitcoin
100100

101101
#define TEMPLATE template <typename Link, typename Key>
102-
#define CLASS head2<Link, Key>
102+
#define CLASS arrayhead<Link, Key>
103103

104-
#include <bitcoin/database/impl/primitives/head2.ipp>
104+
#include <bitcoin/database/impl/primitives/arrayhead.ipp>
105105

106106
#undef CLASS
107107
#undef TEMPLATE

include/bitcoin/database/primitives/arraymap.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <bitcoin/system.hpp>
2323
#include <bitcoin/database/define.hpp>
2424
#include <bitcoin/database/memory/memory.hpp>
25-
#include <bitcoin/database/primitives/head2.hpp>
25+
#include <bitcoin/database/primitives/arrayhead.hpp>
2626
#include <bitcoin/database/primitives/iterator.hpp>
2727
#include <bitcoin/database/primitives/linkage.hpp>
2828
#include <bitcoin/database/primitives/manager.hpp>
@@ -120,7 +120,7 @@ class arraymap
120120
private:
121121
static constexpr auto is_slab = (Size == max_size_t);
122122

123-
using head = database::head2<Link>;
123+
using head = database::arrayhead<Link>;
124124
using manager = database::manager<Link, Key, Size>;
125125

126126
// Thread safe (index/top/push).

0 commit comments

Comments
 (0)