Skip to content
Snippets Groups Projects
Commit cba240e1 authored by Simon Désaulniers's avatar Simon Désaulniers Committed by Adrien Béraud
Browse files

pht: fix invalid comparison, inexact match lookup

parent eb90fffb
No related branches found
No related tags found
No related merge requests found
...@@ -67,26 +67,23 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi, ...@@ -67,26 +67,23 @@ void Pht::lookupStep(Prefix p, std::shared_ptr<int> lo, std::shared_ptr<int> hi,
IndexEntry entry; IndexEntry entry;
entry.unpackValue(*value); entry.unpackValue(*value);
auto add_value = [&](bool better = true) { if (max_common_prefix_len) { /* inexact match case */
vals->emplace_back(std::make_shared<Value>(entry.value)); auto common_bits = Prefix::commonBits(p, entry.prefix);
if (better and max_common_prefix_len)
*max_common_prefix_len = Prefix::commonBits(p, vals->front()->first);
};
if (max_common_prefix_len) {
if (vals->empty()) { if (vals->empty()) {
add_value(); vals->emplace_back(std::make_shared<Value>(entry.value));
} else { *max_common_prefix_len = common_bits;
auto common_bits = Prefix::commonBits(vals->front()->first, p.getPrefix(mid));
if (common_bits == *max_common_prefix_len)
add_value(false);
else if (common_bits > *max_common_prefix_len) {
vals->clear();
add_value();
} }
else {
if (common_bits == *max_common_prefix_len) /* this is the max so far */
vals->emplace_back(std::make_shared<Value>(entry.value));
else if (common_bits > *max_common_prefix_len) { /* new max found! */
vals->clear();
vals->emplace_back(std::make_shared<Value>(entry.value));
*max_common_prefix_len = common_bits;
} }
} }
else if (all_values or entry.prefix == p.content_) } else if (all_values or entry.prefix == p.content_) /* exact match case */
add_value(false); vals->emplace_back(std::make_shared<Value>(entry.value));
} }
return true; return true;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment