diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/ds/PriorityQueue.h | 34 | ||||
| -rw-r--r-- | include/framework/RecordInterface.h | 11 |
2 files changed, 41 insertions, 4 deletions
diff --git a/include/ds/PriorityQueue.h b/include/ds/PriorityQueue.h index a1bfd0a..a8e9ba5 100644 --- a/include/ds/PriorityQueue.h +++ b/include/ds/PriorityQueue.h @@ -21,6 +21,22 @@ struct queue_record { }; template <typename R> +class standard_minheap { +public: + inline bool operator()(const R* a, const R* b) { + return *a < *b; + } +}; + +template <typename R> +class standard_maxheap { +public: + inline bool operator()(const R* a, const R* b) { + return *a > *b; + } +}; + +template <typename R, typename CMP=standard_minheap<R>> class PriorityQueue { public: PriorityQueue(size_t size) : data(size), tail(0) {} @@ -79,6 +95,7 @@ public: private: std::vector<queue_record<R>> data; + CMP cmp; size_t tail; /* @@ -122,11 +139,20 @@ private: inline bool heap_cmp(size_t a, size_t b) { if (data[a].data != data[b].data) { - return *(data[a].data) < *(data[b].data); - } else if (data[a].version != data[b].version) + return cmp(data[a].data, data[b].data); + } else if (data[a].version != data[b].version) { return data[a].version < data[b].version; - else return data[a].data->is_tombstone() && data[b].data->is_tombstone(); - } + } + constexpr bool has_tombstone = requires(const R &r) { + r.is_tombstone(); + }; + + if constexpr (has_tombstone) { + return data[a].data->is_tombstone() && data[b].data->is_tombstone(); + } else { + return false; + } + } }; } diff --git a/include/framework/RecordInterface.h b/include/framework/RecordInterface.h index a3f6814..8d40590 100644 --- a/include/framework/RecordInterface.h +++ b/include/framework/RecordInterface.h @@ -40,6 +40,17 @@ concept KVPInterface = RecordInterface<R> && requires(R r) { r.value; }; +template<typename R> +concept WrappedInterface = RecordInterface<R> && requires(R r, R s, bool b) { + {r.header} -> std::convertible_to<uint32_t>; + r.rec; + {r.set_delete()}; + {r.is_deleted()} -> std::convertible_to<bool>; + {r.set_tombstone(b)}; + {r.is_tombstone()} -> std::convertible_to<bool>; + {r < s} -> std::convertible_to<bool>; +}; + template<RecordInterface R> struct Wrapped { uint32_t header; |