From 1b332b5766b00df4be21825a4d8cd657e7f13433 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Mon, 5 Jun 2023 12:45:40 -0400 Subject: TrieSpline tests+bugfixes --- include/shard/TrieSpline.h | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/shard/TrieSpline.h b/include/shard/TrieSpline.h index 5cd01e3..13753a1 100644 --- a/include/shard/TrieSpline.h +++ b/include/shard/TrieSpline.h @@ -15,7 +15,7 @@ #include #include -#include "PLEX/include/ts/builder.h" +#include "ts/builder.h" #include "ds/PriorityQueue.h" #include "util/Cursor.h" #include "ds/BloomFilter.h" @@ -88,7 +88,7 @@ public: std::sort(base, stop, std::less>()); K min_key = base->rec.key; - K max_key = stop->rec.key; + K max_key = (stop - 1)->rec.key; auto bldr = ts::Builder(min_key, max_key, g_max_error); @@ -104,16 +104,16 @@ public: } if (m_reccnt == 0) { - m_max_key = m_min_key = base->key; - } else if (base->key > m_max_key) { - m_max_key = base->key; - } else if (base->key < m_min_key) { - m_min_key = base->key; + m_max_key = m_min_key = base->rec.key; + } else if (base->rec.key > m_max_key) { + m_max_key = base->rec.key; + } else if (base->rec.key < m_min_key) { + m_min_key = base->rec.key; } base->header &= 1; m_data[m_reccnt++] = *base; - bldr.AddKey(base->key); + bldr.AddKey(base->rec.key); if (m_bf && base->is_tombstone()) { m_tombstone_cnt++; @@ -258,19 +258,24 @@ private: return m_reccnt; } + // if the found location _is_ the key, we're done. + if (m_data[idx].rec.key == key) { + return idx; + } + // if the found location is larger than the key, we need to // move backwards towards the beginning of the array - if (m_data[idx].key > key) { + if (m_data[idx].rec.key > key) { for (ssize_t i=idx; i>=0; i--) { - if (m_data[i].key < key) { + if (m_data[i].rec.key < key) { return i+1; } } // otherwise, we move forward towards the end } else { for (size_t i=idx; i= key) { - return i-1; + if (m_data[i].rec.key >= key) { + return i - 1; } } } -- cgit v1.2.3