From a20edf2b7499fa4f0243d1cfc79ff1ca027fc2f9 Mon Sep 17 00:00:00 2001 From: jbajic Date: Mon, 5 Dec 2022 15:30:10 +0100 Subject: [PATCH] Fix bounds --- src/storage/v3/indices.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/storage/v3/indices.cpp b/src/storage/v3/indices.cpp index 0dbb13481..fc546b594 100644 --- a/src/storage/v3/indices.cpp +++ b/src/storage/v3/indices.cpp @@ -676,23 +676,33 @@ int64_t LabelPropertyIndex::VertexCount(LabelId label, PropertyId property, const std::optional> &upper) const { auto it = index_.find({label, property}); MG_ASSERT(it != index_.end(), "Index for label {} and property {} doesn't exist", label.AsUint(), property.AsUint()); - const auto get_iter = [&it](const auto &value, const auto def) { - if (value) { - auto found_it = it->second.find(value->value()); - if (value->IsInclusive()) { - return found_it; - } - return found_it != it->second.end() ? ++found_it : found_it; - } - return def; - }; - const auto lower_it = get_iter(lower, it->second.begin()); - const auto upper_it = get_iter(upper, it->second.end()); + const auto lower_it = std::invoke( + [&index = it->second](const auto value, const auto def) { + if (value) { + if (value->IsInclusive()) { + return index.lower_bound(value->value()); + } + return index.upper_bound(value->value()); + } + return def; + }, + lower, it->second.begin()); + const auto upper_it = std::invoke( + [&index = it->second](const auto value, const auto def) { + if (value) { + if (value->IsInclusive()) { + return index.upper_bound(value->value()); + } + return index.lower_bound(value->value()); + } + return def; + }, + upper, it->second.end()); return static_cast(std::distance(lower_it, upper_it)); } void LabelPropertyIndex::RunGC() { - // TODO What to do? + // TODO(jbajic) What to do? // for (auto &index_entry : index_) { // index_entry.second.run_gc(); // }