From ff000799c3254f52e0beabbe9c62d10c3fc4178e Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Mon, 15 May 2023 16:48:56 -0400 Subject: Record format generalization Currently, tombstone counting is bugged. But the rest of it appears to be working. --- include/util/Record.h | 86 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 13 deletions(-) (limited to 'include/util/Record.h') diff --git a/include/util/Record.h b/include/util/Record.h index 687e745..ce101f4 100644 --- a/include/util/Record.h +++ b/include/util/Record.h @@ -10,50 +10,110 @@ #pragma once #include +#include #include "util/base.h" namespace de { -template +template +concept RecordInterface = requires(R r, R s) { + r.key; + r.value; + r.header; + + {r.is_tombstone()} -> std::convertible_to; + {r.is_deleted()} -> std::convertible_to; + r.set_delete(); + r.set_tombstone(std::declval); + { r < s } ->std::convertible_to; + { r == s } ->std::convertible_to; + { r.header < s.header } -> std::convertible_to; +}; + +template +concept WeightedRecordInterface = RecordInterface && requires(R r) { + {r.weight} -> std::convertible_to; +}; + +template struct Record { K key; V value; - typename std::conditional::value, W, std::false_type>::type weight; - uint32_t header; + uint32_t header = 0; + + inline void set_delete() { + header |= 2; + } + + inline bool is_deleted() const { + return header & 2; + } + + inline void set_tombstone(bool val=true) { + if (val) { + header |= val; + } else { + header &= 0; + } + } + + inline bool is_tombstone() const { + return header & 1; + } + + inline bool operator<(const Record& other) const { + return key < other.key || (key == other.key && value < other.value); + } - inline bool match(K k, V v, bool is_tombstone) const { - return (key == k) && (value == v) && ((header & 1) == is_tombstone); + inline bool operator==(const Record& other) const { + return key == other.key && value == other.value; } +}; + +template +struct WeightedRecord { + K key; + V value; + W weight = 1; + uint32_t header = 0; - inline void set_delete_status() { + inline void set_delete() { header |= 2; } - inline bool get_delete_status() const { + inline bool is_deleted() const { return header & 2; } + inline void set_tombstone(bool val=true) { + if (val) { + header |= val; + } else { + header &= 0; + } + } + inline bool is_tombstone() const { return header & 1; } - inline int match(const Record* other) const { + inline int match(const WeightedRecord* other) const { return key == other->key && value == other->value; } - inline bool operator<(const Record& other) const { + inline bool operator<(const WeightedRecord& other) const { return key < other.key || (key == other.key && value < other.value); } - inline bool lt(const K& k, const V& v) const { - return key < k || (key == k && value < v); + inline bool operator==(const WeightedRecord& other) const { + return key == other.key && value == other.value; } }; -template -static bool memtable_record_cmp(const Record& a, const Record& b) { +template +static bool memtable_record_cmp(const R& a, const R& b) { return (a.key < b.key) || (a.key == b.key && a.value < b.value) || (a.key == b.key && a.value == b.value && a.header < b.header); } -- cgit v1.2.3