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

Move in-container iteration into containers.h #546

Merged
merged 2 commits into from
Jan 13, 2024

Conversation

SLieve
Copy link
Contributor

@SLieve SLieve commented Jan 9, 2024

This PR moves logic for iterating within containers into containers.h, and adds a new roaring_container_iterator_t struct for that purpose. roaring_container_iterator_t is defined in roaring_types.h because it's exposed through roaring_uint32_iterator_t. In theory it seems possible to hide roaring_uint32_iterator_t, but since exposed already that would have to be done with consideration.

Functionally this should be a no-op. I did make some cosmetic changes and ran clang format on the modified code.

Although it would make the code simpler, I did not include a pointer to the current container and the current typecode in the iterator to avoid duplicating more state. I'm flexible on this though!

include/roaring/roaring.h Outdated Show resolved Hide resolved
include/roaring/roaring_types.h Outdated Show resolved Hide resolved
src/containers/containers.c Outdated Show resolved Hide resolved
include/roaring/roaring.h Outdated Show resolved Hide resolved
Comment on lines 108 to 113
uint16_t value;
bool has_value;
Copy link
Member

Choose a reason for hiding this comment

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

It feels unfortunate that roaring_uint32_iterator_t and roaring_container_iterator_t both have value and has_value fields which seem somewhat duplicated, but I'm not sure it would be reasonable to try to change all uses of roaring_uint32_iterator_t to go through functions to get the current value/has_value (combining the container iterator's value and the high bits of the outer iterator)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion accessors would be an improvement because it allows us to hide the type and change it in the future without ABI incompatibility. It also makes the fields easier to access in other languages. However, it would be an API change.

Copy link
Member

Choose a reason for hiding this comment

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

Hiding the type means requiring an allocation and requiring clients to call a cleanup function though, which can be unfortunate. Right now, there's no allocation, and once they're done iterating, they can just return or whatever.

I honestly think it would be a good idea to do it for roaring_bitmap_t (totally unrelated to your changes), but I'm less sold on the iterator.

That said, we could still use accessors (inline?) even if we don't end up hiding the details of the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fully agreed on roaring_bitmap_t.

Regarding duplication, I've pushed a new commit that removes value and has_value in favor of out parameters. I think it's a bit better, though the function signature of container_iterator_read_into_uint32 is not looking great.

Happy to add accessors to the roaring iterator, though as of right now it won't help reduce the size of the iterator.

include/roaring/roaring_types.h Outdated Show resolved Hide resolved
src/containers/containers.c Outdated Show resolved Hide resolved
src/containers/containers.c Outdated Show resolved Hide resolved
src/containers/containers.c Outdated Show resolved Hide resolved
src/containers/containers.c Outdated Show resolved Hide resolved
@SLieve SLieve force-pushed the container_it branch 3 times, most recently from 3dbce44 to 87c0968 Compare January 11, 2024 22:00
This adds an iterator to iterate over the entries within a container. Extracting
this logic allows reusing it for 64 bit iteration.
This reduces the footprint of the roaring iterator and reduces duplication somewhat.
@lemire lemire merged commit f3ad2f2 into RoaringBitmap:master Jan 13, 2024
25 checks passed
@SLieve SLieve deleted the container_it branch January 22, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants