From e983f209cd6bb6d072d989df44a0d9f313b11ee6 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Tue, 9 May 2023 14:36:51 -0400 Subject: Template/port fixes on utility modules --- include/ds/BitArray.h | 2 +- include/util/Cursor.h | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/ds/BitArray.h b/include/ds/BitArray.h index 1d33d5b..2d785f4 100644 --- a/include/ds/BitArray.h +++ b/include/ds/BitArray.h @@ -14,7 +14,7 @@ #include "util/base.h" -namespace lsm { +namespace de { class BitArray { public: diff --git a/include/util/Cursor.h b/include/util/Cursor.h index 2879830..b9093f4 100644 --- a/include/util/Cursor.h +++ b/include/util/Cursor.h @@ -14,9 +14,10 @@ #include "io/PagedFile.h" namespace de { +template struct Cursor { - Record *ptr; - const Record *end; + Record *ptr; + const Record *end; size_t cur_rec_idx; size_t rec_cnt; @@ -25,8 +26,6 @@ struct Cursor { } }; -static Cursor g_empty_cursor = {0}; - /* * Advance the cursor to the next record. If the cursor is backed by an * iterator, will attempt to advance the iterator once the cursor reaches its @@ -37,16 +36,17 @@ static Cursor g_empty_cursor = {0}; * be updated to be equal to end, and false will be returned. Iterators will * not be closed. */ -inline static bool advance_cursor(Cursor *cur, PagedFileIterator *iter = nullptr) { - cur->ptr++; - cur->cur_rec_idx++; +template +inline static bool advance_cursor(Cursor &cur, PagedFileIterator *iter = nullptr) { + cur.ptr++; + cur.cur_rec_idx++; - if (cur->cur_rec_idx >= cur->rec_cnt) return false; + if (cur.cur_rec_idx >= cur.rec_cnt) return false; - if (cur->ptr >= cur->end) { + if (cur.ptr >= cur.end) { if (iter && iter->next()) { - cur->ptr = (Record*)iter->get_item(); - cur->end = cur->ptr + (PAGE_SIZE / sizeof(Record)); + cur.ptr = (Record*)iter->get_item(); + cur.end = cur.ptr + (PAGE_SIZE / sizeof(Record)); return true; } @@ -62,13 +62,14 @@ inline static bool advance_cursor(Cursor *cur, PagedFileIterator *iter = nullptr * This allows for "peaking" at the next largest element after the current * largest is processed. */ -inline static Cursor *get_next(std::vector &cursors, Cursor *current=&g_empty_cursor) { - const Record *min_rec = nullptr; - Cursor *result = &g_empty_cursor; +template +inline static Cursor *get_next(std::vector> &cursors, Cursor *current=nullptr) { + const Record *min_rec = nullptr; + Cursor *result = nullptr; for (size_t i=0; i< cursors.size(); i++) { - if (cursors[i] == g_empty_cursor) continue; + if (cursors[i] == (Cursor) {0} ) continue; - const Record *rec = (&cursors[i] == current) ? cursors[i].ptr + 1 : cursors[i].ptr; + const Record *rec = (&cursors[i] == current) ? cursors[i].ptr + 1 : cursors[i].ptr; if (rec >= cursors[i].end) continue; if (min_rec == nullptr) { -- cgit v1.2.3