Skip to content

Commit 135a6c2

Browse files
committed
Style, comments on hashhead.
1 parent 946e458 commit 135a6c2

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

include/bitcoin/database/impl/primitives/hashhead.ipp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ TEMPLATE
146146
inline bool CLASS::push(const Link& current, bytes& next,
147147
const Link& index) NOEXCEPT
148148
{
149-
return set_cell(next, current, index) != fault_cell;
149+
return set_cell(next, current, index) != terminal;
150150
}
151151

152152
TEMPLATE
153153
inline bool CLASS::push(bool& collision, const Link& current, bytes& next,
154154
const Key& key) NOEXCEPT
155155
{
156156
const auto previous = set_cell(next, current, index(key));
157-
if (previous == fault_cell)
157+
if (previous == terminal)
158158
return false;
159159

160160
// Caller searches Link{ next } for duplicate in case of filter collision.
@@ -172,7 +172,7 @@ inline CLASS::cell CLASS::get_cell(const Link& index) const NOEXCEPT
172172
using namespace system;
173173
const auto raw = file_.get_raw(link_to_position(index));
174174
if (is_null(raw))
175-
return fault_cell;
175+
return terminal;
176176

177177
if constexpr (aligned)
178178
{
@@ -205,7 +205,7 @@ inline CLASS::cell CLASS::set_cell(bytes& next, const Link& current,
205205
using namespace system;
206206
const auto raw = file_.get_raw(link_to_position(index));
207207
if (is_null(raw))
208-
return fault_cell;
208+
return terminal;
209209

210210
if constexpr (aligned)
211211
{
@@ -249,7 +249,7 @@ inline CLASS::cell CLASS::set_cell(bytes& next, const Link& current,
249249
TEMPLATE
250250
constexpr CLASS::link CLASS::to_link(cell value) NOEXCEPT
251251
{
252-
if (value == fault_cell)
252+
if (value == terminal)
253253
return {};
254254

255255
using namespace system;
@@ -258,26 +258,30 @@ constexpr CLASS::link CLASS::to_link(cell value) NOEXCEPT
258258
}
259259

260260
TEMPLATE
261-
constexpr CLASS::cell CLASS::to_filter(cell value) NOEXCEPT
261+
constexpr CLASS::cell CLASS::to_cell(cell previous, link current) NOEXCEPT
262262
{
263-
// TODO: mask link bits and return cell (private use).
264-
return value;
265-
}
266-
267-
TEMPLATE
268-
constexpr CLASS::cell CLASS::to_cell(cell /*previous*/, link current) NOEXCEPT
269-
{
270-
// TODO: merge link into previous cell and update fingers.
263+
// [--------------filter---------------][--------------link--------------]
264+
// [[sen][--------fingerprints--------]][--------------link--------------]
265+
266+
// [[111][1111111111111111111111111111]] terminal (empty/default)
267+
// [[000][1111111111111111111111111111]] 1 FPs
268+
// [[001][2222222222222211111111111111]] 2 FPs
269+
// [[010][3333333333222222222111111111]] 3 FPs
270+
// [[011][4444444333333322222221111111]] 4 FPs
271+
// [[100][5555554444443333332222211111]] 5 FPs
272+
// [[101][6666655555444443333322221111]] 6 FPs
273+
// [[110][7777666655554444333322221111]] 7 FPs
274+
// [[111][0000000000000000000000000000]] overflow
271275
return current;
272276
}
273277

274278
TEMPLATE
275-
constexpr bool CLASS::is_collision(cell value, const Key& /*key*/) NOEXCEPT
279+
constexpr bool CLASS::is_collision(cell value, const Key& key) NOEXCEPT
276280
{
277-
if (value == fault_cell)
281+
if (value == terminal)
278282
return false;
279283

280-
// TODO: true if overflow sentinel or any matching finger.
284+
// TODO: true if overflow sentinel or any matching FP.
281285
return true;
282286
}
283287

include/bitcoin/database/primitives/hashhead.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ class hashhead
8888
using link = Link::integer;
8989
using cell = unsigned_type<cell_size>;
9090
using filter = unsigned_type<filter_size>;
91-
static constexpr cell fault_cell = system::bit_all<cell>;
91+
static constexpr cell terminal = system::bit_all<cell>;
9292
static constexpr bool aligned = (cell_size == sizeof(cell));
9393
static_assert(link_bits + filter_bits == to_bits(cell_size));
9494
static_assert(std::atomic<cell>::is_always_lock_free);
9595
static_assert(is_nonzero(Link::size));
9696

9797
static constexpr link to_link(cell value) NOEXCEPT;
98-
static constexpr cell to_filter(cell value) NOEXCEPT;
98+
////static constexpr cell to_filter(cell value) NOEXCEPT;
9999
static constexpr cell to_cell(cell previous, link current) NOEXCEPT;
100100
static constexpr bool is_collision(cell value, const Key& key) NOEXCEPT;
101101
inline cell get_cell(const Link& index) const NOEXCEPT;

0 commit comments

Comments
 (0)