summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ds/BloomFilter.h4
-rw-r--r--include/ds/PriorityQueue.h28
-rw-r--r--include/util/Record.h22
3 files changed, 25 insertions, 29 deletions
diff --git a/include/ds/BloomFilter.h b/include/ds/BloomFilter.h
index dbaab2f..fddd1fb 100644
--- a/include/ds/BloomFilter.h
+++ b/include/ds/BloomFilter.h
@@ -14,9 +14,9 @@
#include "ds/BitArray.h"
#include "util/hash.h"
#include "util/base.h"
-#include "util/record.h"
+#include "util/Record.h"
-namespace lsm {
+namespace de {
class BloomFilter {
public:
diff --git a/include/ds/PriorityQueue.h b/include/ds/PriorityQueue.h
index 49f3e41..290d5c8 100644
--- a/include/ds/PriorityQueue.h
+++ b/include/ds/PriorityQueue.h
@@ -1,5 +1,5 @@
/*
- * include/ds/PriorityQueue.h
+ * include/ds/BloomFilter.h
*
* Copyright (C) 2023 Douglas Rumbaugh <drumbaugh@psu.edu>
* Dong Xie <dongx@psu.edu>
@@ -12,16 +12,18 @@
#include <vector>
#include <cassert>
-#include "util/record.h"
+#include "util/Record.h"
-namespace lsm {
+namespace de {
+template <typename K, typename V, typename W=void>
struct queue_record {
- const char *data;
+ const Record<K, V, W> *data;
size_t version;
};
+template <typename K, typename V, typename W=void>
class PriorityQueue {
public:
PriorityQueue(size_t size) : data(size), tail(0) {}
@@ -52,7 +54,7 @@ public:
}
}
- void push(const char* record, size_t version=0) {
+ void push(const Record<K, V, W>* record, size_t version=0) {
assert(tail != this->data.size());
size_t new_idx = this->tail++;
@@ -65,7 +67,7 @@ public:
}
- queue_record peek(size_t depth=0) {
+ queue_record<K, V, W> peek(size_t depth=0) {
ssize_t idx = 0;
size_t cur_depth = 0;
@@ -79,7 +81,7 @@ public:
}
private:
- std::vector<queue_record> data;
+ std::vector<queue_record<K, V, W>> data;
size_t tail;
/*
@@ -122,13 +124,11 @@ private:
}
inline bool heap_cmp(size_t a, size_t b) {
- auto cmp = record_cmp(this->data[a].data, this->data[b].data);
- if (cmp == 0) {
- if (this->data[a].version != this->data[b].version)
- return this->data[a].version < this->data[b].version;
- else return is_tombstone(this->data[a].data) && is_tombstone(this->data[b].data);
- }
- return cmp == -1;
+ if (!data[a].data->match(data[b].data)) {
+ return *(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();
}
};
diff --git a/include/util/Record.h b/include/util/Record.h
index 7e64959..687e745 100644
--- a/include/util/Record.h
+++ b/include/util/Record.h
@@ -15,18 +15,14 @@
namespace de {
-typedef uint32_t hdr_t;
-typedef uint64_t key_t;
-typedef uint32_t value_t;
-typedef uint64_t weight_t;
-
+template <typename K, typename V, typename W=void>
struct Record {
- key_t key;
- value_t value;
- hdr_t header;
- weight_t weight;
+ K key;
+ V value;
+ typename std::conditional<!std::is_same<W, void>::value, W, std::false_type>::type weight;
+ uint32_t header;
- inline bool match(key_t k, value_t v, bool is_tombstone) const {
+ inline bool match(K k, V v, bool is_tombstone) const {
return (key == k) && (value == v) && ((header & 1) == is_tombstone);
}
@@ -50,14 +46,14 @@ struct Record {
return key < other.key || (key == other.key && value < other.value);
}
- inline bool lt(const key_t& k, const value_t& v) const {
+ inline bool lt(const K& k, const V& v) const {
return key < k || (key == k && value < v);
}
};
-static_assert(sizeof(Record) == 24, "Record is not 24 bytes long.");
-static bool memtable_record_cmp(const Record& a, const Record& b) {
+template <typename K, typename V, typename W=void>
+static bool memtable_record_cmp(const Record<K, V, W>& a, const Record<K, V, W>& 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);
}