From 418e9b079e559c86f3a5b276f712ad2f5d66533c Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Tue, 9 May 2023 17:59:37 -0400 Subject: Ported over IRS with unit tests --- include/framework/MutableBuffer.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'include/framework') diff --git a/include/framework/MutableBuffer.h b/include/framework/MutableBuffer.h index b3acfee..42bc9a7 100644 --- a/include/framework/MutableBuffer.h +++ b/include/framework/MutableBuffer.h @@ -14,6 +14,7 @@ #include #include #include +#include #include "util/base.h" #include "util/bf_config.h" @@ -46,7 +47,32 @@ public: if (m_tombstone_filter) delete m_tombstone_filter; } - int append(const K& key, const V& value, W weight = 1, bool is_tombstone = false) { + template ::value>> + int append(const K& key, const V& value, bool is_tombstone = false) { + static_assert(std::is_same::value); + if (is_tombstone && m_tombstonecnt + 1 > m_tombstone_cap) return 0; + + int32_t pos = 0; + if ((pos = try_advance_tail()) == -1) return 0; + + m_data[pos].key = key; + m_data[pos].value = value; + m_data[pos].header = ((pos << 2) | (is_tombstone ? 1 : 0)); + + if (is_tombstone) { + m_tombstonecnt.fetch_add(1); + if (m_tombstone_filter) m_tombstone_filter->insert(key); + } + + m_weight.fetch_add(1); + return 1; + } + + template ::value>> + int append(const K& key, const V& value, W_ weight=1, bool is_tombstone = false) { + static_assert(!std::is_same::value); if (is_tombstone && m_tombstonecnt + 1 > m_tombstone_cap) return 0; int32_t pos = 0; @@ -82,6 +108,7 @@ public: return 1; } + bool truncate() { m_tombstonecnt.store(0); m_reccnt.store(0); -- cgit v1.2.3