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

fix: introduce init functions to avoid warnings. #631

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions include/roaring/art/art.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ typedef struct art_iterator_s {
art_iterator_frame_t frames[ART_KEY_BYTES + 1];
} art_iterator_t;

/**
* Initialize the iterator to zero.
*/
void art_iterator_init(art_iterator_t *iterator);

/**
* Creates an iterator initialzed to the first or last entry in the ART,
* depending on `first`. The iterator is not valid if there are no entries in
Expand Down
5 changes: 5 additions & 0 deletions include/roaring/roaring64.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ typedef struct roaring64_bulk_context_s {
roaring64_leaf_t *leaf;
} roaring64_bulk_context_t;

/**
* Initialize a bulk context to zero.
*/
void roaring64_bulk_context_init(roaring64_bulk_context_t *context);

/**
* Dynamically allocates a new bitmap (initially empty).
* Client is responsible for calling `roaring64_bitmap_free()`.
Expand Down
13 changes: 10 additions & 3 deletions src/art/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ namespace roaring {
namespace internal {
#endif

void art_iterator_init(art_iterator_t *iterator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit/style: I suggest moving this to line 123 or somewhere around there, so all typedefs are at the top before utility functions.

memset(iterator, 0, sizeof(art_iterator_t));
}

typedef uint8_t art_typecode_t;

// Aliasing with a "leaf" naming so that its purpose is clearer in the context
Expand Down Expand Up @@ -1670,7 +1674,8 @@ static bool art_node_iterator_lower_bound(const art_node_t *node,
}

art_iterator_t art_init_iterator(const art_t *art, bool first) {
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
art_iterator_t iterator;
art_iterator_init(&iterator);
if (art->root == NULL) {
return iterator;
}
Expand Down Expand Up @@ -1727,15 +1732,17 @@ bool art_iterator_lower_bound(art_iterator_t *iterator,
}

art_iterator_t art_lower_bound(const art_t *art, const art_key_chunk_t *key) {
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
art_iterator_t iterator;
art_iterator_init(&iterator);
if (art->root != NULL) {
art_node_iterator_lower_bound(art->root, &iterator, key);
}
return iterator;
}

art_iterator_t art_upper_bound(const art_t *art, const art_key_chunk_t *key) {
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
art_iterator_t iterator;
art_iterator_init(&iterator);
if (art->root != NULL) {
if (art_node_iterator_lower_bound(art->root, &iterator, key) &&
art_compare_keys(iterator.key, key) == 0) {
Expand Down
14 changes: 9 additions & 5 deletions src/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ namespace roaring {
namespace api {
#endif

// TODO: Copy on write.
// TODO: Error on failed allocation.
void roaring64_bulk_context_init(roaring64_bulk_context_t *context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit/style: Same here, suggest moving it below the typedefs

memset(context, 0, sizeof(roaring64_bulk_context_t));
}

typedef struct roaring64_bitmap_s {
art_t art;
Expand Down Expand Up @@ -224,7 +225,8 @@ roaring64_bitmap_t *roaring64_bitmap_of_ptr(size_t n_args,

roaring64_bitmap_t *roaring64_bitmap_of(size_t n_args, ...) {
roaring64_bitmap_t *r = roaring64_bitmap_create();
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
roaring64_bulk_context_t context;
roaring64_bulk_context_init(&context);
va_list ap;
va_start(ap, n_args);
for (size_t i = 0; i < n_args; i++) {
Expand Down Expand Up @@ -317,7 +319,8 @@ void roaring64_bitmap_add_many(roaring64_bitmap_t *r, size_t n_args,
return;
}
const uint64_t *end = vals + n_args;
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
roaring64_bulk_context_t context;
roaring64_bulk_context_init(&context);
for (const uint64_t *current_val = vals; current_val != end;
current_val++) {
roaring64_bitmap_add_bulk(r, &context, *current_val);
Expand Down Expand Up @@ -641,7 +644,8 @@ void roaring64_bitmap_remove_many(roaring64_bitmap_t *r, size_t n_args,
return;
}
const uint64_t *end = vals + n_args;
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
roaring64_bulk_context_t context;
roaring64_bulk_context_init(&context);
for (const uint64_t *current_val = vals; current_val != end;
current_val++) {
roaring64_bitmap_remove_bulk(r, &context, *current_val);
Expand Down
Loading