From 0cf160ee68d37be93665e665ef22ae6e211a157d Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Mon, 22 May 2023 14:58:22 -0400 Subject: More updates/restructuring --- include/framework/RecordInterface.h | 121 ++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 include/framework/RecordInterface.h (limited to 'include/framework/RecordInterface.h') diff --git a/include/framework/RecordInterface.h b/include/framework/RecordInterface.h new file mode 100644 index 0000000..8afd90a --- /dev/null +++ b/include/framework/RecordInterface.h @@ -0,0 +1,121 @@ +/* + * include/framework/RecordInterface.h + * + * Copyright (C) 2023 Douglas Rumbaugh + * Dong Xie + * + * All rights reserved. Published under the Modified BSD License. + * + */ +#pragma once + +#include +#include + +#include "util/base.h" + +namespace de { + +template +concept RecordInterface = requires(R r, R s) { + r.key; + r.value; + + { r < s } ->std::convertible_to; + { r == s } ->std::convertible_to; +}; + +template +struct WrappedRecord { + R rec; + uint32_t header; + + 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; + } +}; + +template +concept WeightedRecordInterface = RecordInterface && requires(R r) { + {r.weight} -> std::convertible_to; +}; + +template +struct Record { + K key; + V value; + uint32_t header = 0; + + inline bool operator<(const Record& other) const { + return key < other.key || (key == other.key && value < other.value); + } + + 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() { + 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 int match(const WeightedRecord* other) const { + return key == other->key && value == other->value; + } + + inline bool operator<(const WeightedRecord& other) const { + return key < other.key || (key == other.key && value < other.value); + } + + inline bool operator==(const WeightedRecord& other) const { + return key == other.key && value == other.value; + } +}; + + +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