From b00682429988f17152e7573ffeffa1cecfdd3d3a Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Mon, 29 May 2023 12:33:58 -0400 Subject: Tests and bugfixes for framework --- include/shard/WIRS.h | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'include/shard/WIRS.h') diff --git a/include/shard/WIRS.h b/include/shard/WIRS.h index 4c7563f..5b610c7 100644 --- a/include/shard/WIRS.h +++ b/include/shard/WIRS.h @@ -23,6 +23,8 @@ #include "util/bf_config.h" #include "framework/MutableBuffer.h" #include "framework/RecordInterface.h" +#include "framework/ShardInterface.h" +#include "framework/QueryInterface.h" namespace de { @@ -34,8 +36,6 @@ struct wirs_query_parms { decltype(R::key) upper_bound; }; -class InternalLevel; - template class WIRSQuery; @@ -60,7 +60,6 @@ struct WIRSState { template class WIRS { - friend class InternalLevel; private: typedef decltype(R::key) K; @@ -82,9 +81,11 @@ public: size_t offset = 0; m_reccnt = 0; - auto base = buffer->sorted_output(); + auto base = buffer->get_data(); auto stop = base + buffer->get_record_count(); + std::sort(base, stop, memtable_record_cmp); + while (base < stop) { if (!(base->is_tombstone()) && (base + 1) < stop) { if (*base == *(base + 1) && (base + 1)->is_tombstone()) { @@ -186,7 +187,7 @@ public: } R *point_lookup(R &rec, bool filter=false) { - if (filter && !m_bf.lookup(rec.key)) { + if (filter && !m_bf->lookup(rec.key)) { return nullptr; } @@ -292,6 +293,29 @@ private: m_root = construct_wirs_node(weights, 0, n_groups-1); } + struct wirs_node* construct_wirs_node(const std::vector& weights, size_t low, size_t high) { + if (low == high) { + return new wirs_node{nullptr, nullptr, low, high, weights[low], new Alias({1.0})}; + } else if (low > high) return nullptr; + + std::vector node_weights; + W sum = 0; + for (size_t i = low; i < high; ++i) { + node_weights.emplace_back(weights[i]); + sum += weights[i]; + } + + for (auto& w: node_weights) + if (sum) w /= sum; + else w = 1.0 / node_weights.size(); + + + size_t mid = (low + high) / 2; + return new wirs_node{construct_wirs_node(weights, low, mid), + construct_wirs_node(weights, mid + 1, high), + low, high, sum, new Alias(node_weights)}; + } + void free_tree(struct wirs_node* node) { if (node) { delete node->alias; @@ -308,7 +332,7 @@ private: size_t m_reccnt; size_t m_tombstone_cnt; size_t m_group_size; - BloomFilter m_bf; + BloomFilter *m_bf; }; @@ -394,7 +418,8 @@ public: return output; } - static void delete_query_state(wirs_query_parms *parameters) { + static void delete_query_state(void *parm) { + wirs_query_parms *parameters = parm; delete parameters; } -- cgit v1.2.3