Skip to content

Commit 1d20724

Browse files
committed
Enable point table insert search tracking.
1 parent a6cd373 commit 1d20724

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ inline bool CLASS::put(bool& duplicate, const memory_ptr& ptr,
377377
if (!write(previous_head, ptr, link, key, element))
378378
return false;
379379

380+
if (!previous_head.is_terminal())
381+
counter_.fetch_add(one, std::memory_order_relaxed);
382+
380383
duplicate = !first(ptr, previous_head, key).is_terminal();
381384
return true;
382385
}
@@ -552,7 +555,11 @@ bool CLASS::write(Link& previous, const memory_ptr& ptr, const Link& link,
552555
return false;
553556

554557
// If filter collision set previous stack head for conflict resolution.
555-
previous = collision ? next : Link::terminal;
558+
if (collision)
559+
previous = next;
560+
else
561+
previous = Link::terminal;
562+
556563
return true;
557564
}
558565

include/bitcoin/database/primitives/hashmap.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_HASHMAP_HPP
2020
#define LIBBITCOIN_DATABASE_PRIMITIVES_HASHMAP_HPP
2121

22+
#include <atomic>
2223
#include <bitcoin/system.hpp>
2324
#include <bitcoin/database/define.hpp>
2425
#include <bitcoin/database/memory/memory.hpp>
@@ -78,6 +79,12 @@ class hashmap
7879
/// Increase count as neccesary to specified.
7980
bool expand(const Link& count) NOEXCEPT;
8081

82+
/// Count of puts resulting in table body search to detect duplication.
83+
size_t search_count() const NOEXCEPT
84+
{
85+
return counter_.load(std::memory_order_relaxed);
86+
}
87+
8188
/// Errors.
8289
/// -----------------------------------------------------------------------
8390

@@ -226,6 +233,7 @@ class hashmap
226233

227234
// Thread safe.
228235
body body_;
236+
std::atomic<size_t> counter_{};
229237
};
230238

231239
template <typename Element>

0 commit comments

Comments
 (0)