diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/shard/TrieSpline.h | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/include/shard/TrieSpline.h b/include/shard/TrieSpline.h index b068313..d09d2a6 100644 --- a/include/shard/TrieSpline.h +++ b/include/shard/TrieSpline.h @@ -279,6 +279,10 @@ private: } + if (m_data[idx].rec.key > key && idx > 0 && m_data[idx-1].rec.key <= key) { + return idx-1; + } + return (m_data[idx].rec.key <= key) ? idx : m_reccnt; } @@ -329,10 +333,17 @@ public: } auto ptr = ts->get_record_at(s->start_idx); - size_t i = 0; - while (ptr[i].rec.key <= p->upper_bound && i < s->stop_idx - s->start_idx) { - records.emplace_back(ptr[i]); - i++; + + // roll the pointer forward to the first record that is + // greater than or equal to the lower bound. + while(ptr->rec.key < p->lower_bound) { + ptr++; + } + + + while (ptr->rec.key <= p->upper_bound && ptr < ts->m_data + s->stop_idx) { + records.emplace_back(*ptr); + ptr++; } return records; @@ -356,12 +367,20 @@ public: } static std::vector<R> merge(std::vector<std::vector<R>> &results, void *parms) { + size_t total = 0; + for (size_t i=0; i<results.size(); i++) { + total += results[i].size(); + } + + if (total == 0) { + return std::vector<R>(); + } + std::vector<R> output; + output.reserve(total); for (size_t i=0; i<results.size(); i++) { - for (size_t j=0; j<results[i].size(); j++) { - output.emplace_back(results[i][j]); - } + std::move(results[i].begin(), results[i].end(), std::back_inserter(output)); } return output; |