Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve consistency in the C++ interface #653

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Code style fixes
cubicYYY committed Aug 30, 2024
commit 14824c88ebdc68b2ab4d37181e5e56eb3639bb30
3 changes: 2 additions & 1 deletion benchmarks/containsmulti_benchmark.c
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

#include "benchmark.h"
#include "numbersfromtextfiles.h"
#include "portability.h"
#include "random.h"

void contains_multi_via_contains(roaring_bitmap_t* bm, const uint32_t* values,
@@ -19,7 +20,7 @@ void contains_multi_via_contains(roaring_bitmap_t* bm, const uint32_t* values,

void contains_multi_bulk(roaring_bitmap_t* bm, const uint32_t* values,
bool* results, const size_t count) {
roaring_bulk_context_t context = {0, 0, 0, 0};
roaring_bulk_context_t context = CROARING_ZERO_INITIALIZER;
for (size_t i = 0; i < count; ++i) {
results[i] = roaring_bitmap_contains_bulk(bm, &context, values[i]);
}
3 changes: 1 addition & 2 deletions cpp/roaring64map.hh
Original file line number Diff line number Diff line change
@@ -1709,8 +1709,7 @@ class Roaring64Map {
/**
* Used to go through the set bits. Not optimally fast, but convenient.
*
* strongly recommend not to implicitly construct this iterator:
* implicit construction may be prohibited in the future.
* Recommend to explicitly construct this iterator.
*/
class Roaring64MapSetBitBiDirectionalIterator {
public:
8 changes: 6 additions & 2 deletions include/roaring/roaring.h
Original file line number Diff line number Diff line change
@@ -387,7 +387,9 @@ void roaring_bitmap_add_range_closed(roaring_bitmap_t *r, uint32_t min,
*/
inline void roaring_bitmap_add_range(roaring_bitmap_t *r, uint64_t min,
uint64_t max) {
if (max <= min || min > (uint64_t)UINT32_MAX + 1) return;
if (max <= min || min > (uint64_t)UINT32_MAX + 1) {
return;
}
roaring_bitmap_add_range_closed(r, (uint32_t)min, (uint32_t)(max - 1));
}

@@ -407,7 +409,9 @@ void roaring_bitmap_remove_range_closed(roaring_bitmap_t *r, uint32_t min,
*/
inline void roaring_bitmap_remove_range(roaring_bitmap_t *r, uint64_t min,
uint64_t max) {
if (max <= min || min > (uint64_t)UINT32_MAX + 1) return;
if (max <= min || min > (uint64_t)UINT32_MAX + 1) {
return;
}
roaring_bitmap_remove_range_closed(r, (uint32_t)min, (uint32_t)(max - 1));
}

17 changes: 11 additions & 6 deletions src/roaring.c
Original file line number Diff line number Diff line change
@@ -2013,8 +2013,9 @@ static void inplace_fully_flip_container(roaring_array_t *x1_arr, uint16_t hb) {
roaring_bitmap_t *roaring_bitmap_flip(const roaring_bitmap_t *x1,
uint64_t range_start,
uint64_t range_end) {
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1)
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1) {
return roaring_bitmap_copy(x1);
SLieve marked this conversation as resolved.
Show resolved Hide resolved
}
return roaring_bitmap_flip_closed(x1, (uint32_t)range_start,
(uint32_t)(range_end - 1));
}
@@ -2073,8 +2074,9 @@ roaring_bitmap_t *roaring_bitmap_flip_closed(const roaring_bitmap_t *x1,

void roaring_bitmap_flip_inplace(roaring_bitmap_t *x1, uint64_t range_start,
uint64_t range_end) {
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1)
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1) {
return;
}
roaring_bitmap_flip_inplace_closed(x1, (uint32_t)range_start,
(uint32_t)(range_end - 1));
}
@@ -2847,8 +2849,9 @@ bool roaring_bitmap_contains(const roaring_bitmap_t *r, uint32_t val) {
*/
bool roaring_bitmap_contains_range(const roaring_bitmap_t *r,
uint64_t range_start, uint64_t range_end) {
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1)
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1) {
return true;
}
return roaring_bitmap_contains_range_closed(r, (uint32_t)range_start,
(uint32_t)(range_end - 1));
}
@@ -2860,10 +2863,12 @@ bool roaring_bitmap_contains_range(const roaring_bitmap_t *r,
bool roaring_bitmap_contains_range_closed(const roaring_bitmap_t *r,
uint32_t range_start,
uint32_t range_end) {
if (range_start > range_end)
return true; // empty range are always contained!
if (range_end == range_start)
if (range_start > range_end) {
return true;
} // empty range are always contained!
if (range_end == range_start) {
return roaring_bitmap_contains(r, (uint32_t)range_start);
}
uint16_t hb_rs = (uint16_t)(range_start >> 16);
uint16_t hb_re = (uint16_t)(range_end >> 16);
const int32_t span = hb_re - hb_rs;