Skip to content

Commit

Permalink
Minor optimize C++ roaring64 contains and addMany (RoaringBitmap#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU authored Feb 8, 2024
1 parent e1e2359 commit 04c9af2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cpp/roaring64map.hh
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,17 @@ class Roaring64Map {
// assuming that adjacent values will belong to the same inner bitmap.
Roaring *last_inner_bitmap = nullptr;
uint32_t last_value_high = 0;
BulkContext last_bulk_context;
for (size_t lcv = 0; lcv < n_args; lcv++) {
auto value = vals[lcv];
auto value_high = highBytes(value);
auto value_low = lowBytes(value);
if (last_inner_bitmap == nullptr || value_high != last_value_high) {
last_inner_bitmap = &lookupOrCreateInner(value_high);
last_value_high = value_high;
last_bulk_context = BulkContext{};
}
last_inner_bitmap->add(value_low);
last_inner_bitmap->addBulk(last_bulk_context, value_low);
}
}

Expand Down Expand Up @@ -473,12 +475,18 @@ class Roaring64Map {
* Check if value x is present
*/
bool contains(uint32_t x) const {
return roarings.count(0) == 0 ? false : roarings.at(0).contains(x);
auto iter = roarings.find(0);
if (iter == roarings.end()) {
return false;
}
return iter->second.contains(x);
}
bool contains(uint64_t x) const {
return roarings.count(highBytes(x)) == 0
? false
: roarings.at(highBytes(x)).contains(lowBytes(x));
auto iter = roarings.find(highBytes(x));
if (iter == roarings.end()) {
return false;
}
return iter->second.contains(lowBytes(x));
}

/**
Expand Down

0 comments on commit 04c9af2

Please sign in to comment.