Skip to content

Commit

Permalink
Merge pull request #137 from Dr-Emann/2_0_for_real
Browse files Browse the repository at this point in the history
Add some tests which will fail until we get a 4.0.1 of CRoaring. Don't merge until we update again once CRoaring is fixed.

Also, include the matching CRoaring version in the readme and some clarification on versioning, this will hopefully help clarify somewhat the questions raised in #136. Link to the rendered added section: https://github.com/Dr-Emann/croaring-rs/blob/2_0_for_real/README.md#croaring-version
  • Loading branch information
Dr-Emann authored Jul 4, 2024
2 parents bca14a8 + 78c9838 commit 0d3ff0c
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 189 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target
.DS_Store
.idea
.idea
README.md.tmp
Cargo.toml.tmp
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test:
croaring_release_url_base = https://github.com/RoaringBitmap/CRoaring/releases/download

# Fetch the c source amalgamation from a tagged CRoaring release (like `make version=0.9.3 update_croaring`)
update_croaring: download_croaring bindgen
update_croaring: download_croaring bindgen update_readme_croaring_version update_croaring_sys_version

download_croaring:
rm -f '$(croaring_source)/roaring.c' '$(croaring_source)/roaring.h' '$(croaring_source)/roaring.hh'
Expand All @@ -35,6 +35,19 @@ bindgen:
-o bindgen_bundled_version.rs \
roaring.h


# sed -i is a GNU extension, so we use a temporary file explicitly
update_readme_croaring_version:
@echo "Updating README.md with CRoaring version $(version)"
@sed -r -e 's_\[CRoaring version `[0-9]+\.[0-9]+\.[0-9]+`\]\([^\)]+\)_[CRoaring version `$(version)`](https://github.com/RoaringBitmap/CRoaring/releases/tag/v$(version))_' README.md > README.md.tmp
@mv README.md.tmp README.md

# We don't always want to update the version of croaring-sys dependency in croaring, but we always want to update croaring-sys
update_croaring_sys_version:
@echo "Updating croaring-sys version in Cargo.toml to $(version)"
@sed -r -e 's/^version = ".*"/version = "$(version)"/' croaring-sys/Cargo.toml > croaring-sys/Cargo.toml.tmp
@mv croaring-sys/Cargo.toml.tmp croaring-sys/Cargo.toml

# Build a c program to (re)generate the example serialized files for testing
test_serialization_files:
cd croaring/tests/data/ && \
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,10 @@ cargo bench
### Documentation

Current documentation is available at https://docs.rs/croaring/latest/croaring/

## CRoaring Version

This crate uses [CRoaring version `4.1.0`](https://github.com/RoaringBitmap/CRoaring/releases/tag/v4.1.0).
The version of this crate does not necessarily match the version of CRoaring: the major version of the crate is only
incremented when there are breaking changes in the Rust API: It is possible (and has happened) that breaking changes
in the CRoaring C API do not necessitate a major version bump in this crate.
28 changes: 20 additions & 8 deletions croaring-sys/CRoaring/bindgen_bundled_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ pub const ROARING_VERSION_MAJOR: _bindgen_ty_1 = 4;
pub const ROARING_VERSION_MINOR: _bindgen_ty_1 = 0;
pub const ROARING_VERSION_REVISION: _bindgen_ty_1 = 0;
pub type _bindgen_ty_1 = ::core::ffi::c_uint;
extern "C" {
#[doc = " result might be undefined when input_num is zero"]
pub fn roaring_trailing_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
}
extern "C" {
#[doc = " result might be undefined when input_num is zero"]
pub fn roaring_leading_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
}
#[doc = " Roaring arrays are array-based key-value pairs having containers as values\n and 16-bit integer keys. A roaring bitmap might be implemented as such."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -73,14 +81,6 @@ pub struct roaring_container_iterator_s {
}
#[doc = " Roaring-internal type used to iterate within a roaring container."]
pub type roaring_container_iterator_t = roaring_container_iterator_s;
extern "C" {
#[doc = " result might be undefined when input_num is zero"]
pub fn roaring_trailing_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
}
extern "C" {
#[doc = " result might be undefined when input_num is zero"]
pub fn roaring_leading_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct bitset_s {
Expand Down Expand Up @@ -925,6 +925,10 @@ extern "C" {
#[doc = " Remove all values in range [min, max]."]
pub fn roaring64_bitmap_remove_range_closed(r: *mut roaring64_bitmap_t, min: u64, max: u64);
}
extern "C" {
#[doc = " Empties the bitmap."]
pub fn roaring64_bitmap_clear(r: *mut roaring64_bitmap_t);
}
extern "C" {
#[doc = " Returns true if the provided value is present."]
pub fn roaring64_bitmap_contains(r: *const roaring64_bitmap_t, val: u64) -> bool;
Expand Down Expand Up @@ -977,6 +981,14 @@ extern "C" {
max: u64,
) -> u64;
}
extern "C" {
#[doc = " Returns the number of elements in the range [min, max]"]
pub fn roaring64_bitmap_range_closed_cardinality(
r: *const roaring64_bitmap_t,
min: u64,
max: u64,
) -> u64;
}
extern "C" {
#[doc = " Returns true if the bitmap is empty (cardinality is zero)."]
pub fn roaring64_bitmap_is_empty(r: *const roaring64_bitmap_t) -> bool;
Expand Down
46 changes: 33 additions & 13 deletions croaring-sys/CRoaring/roaring.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// !!! DO NOT EDIT - THIS IS AN AUTO-GENERATED FILE !!!
// Created by amalgamation.sh on 2024-05-13T21:29:25Z
// Created by amalgamation.sh on 2024-07-03T21:30:32Z

/*
* The CRoaring project is under a dual license (Apache/MIT).
Expand Down Expand Up @@ -10770,7 +10770,7 @@ 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 = CROARING_ZERO_INITIALIZER;
if (art->root == NULL) {
return iterator;
}
Expand All @@ -10793,8 +10793,11 @@ bool art_iterator_lower_bound(art_iterator_t *iterator,
// a valid key. Start from the root.
iterator->frame = 0;
iterator->depth = 0;
return art_node_iterator_lower_bound(art_iterator_node(iterator),
iterator, key);
art_node_t *root = art_iterator_node(iterator);
if (root == NULL) {
return false;
}
return art_node_iterator_lower_bound(root, iterator, key);
}
int compare_result =
art_compare_prefix(iterator->key, 0, key, 0, ART_KEY_BYTES);
Expand Down Expand Up @@ -10827,15 +10830,15 @@ 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 = CROARING_ZERO_INITIALIZER;
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 = CROARING_ZERO_INITIALIZER;
if (art->root != NULL) {
if (art_node_iterator_lower_bound(art->root, &iterator, key) &&
art_compare_keys(iterator.key, key) == 0) {
Expand Down Expand Up @@ -19469,7 +19472,7 @@ roaring_bitmap_t *roaring_bitmap_of(size_t n_args, ...) {
// todo: could be greatly optimized but we do not expect this call to ever
// include long lists
roaring_bitmap_t *answer = roaring_bitmap_create();
roaring_bulk_context_t context = {0, 0, 0, 0};
roaring_bulk_context_t context = CROARING_ZERO_INITIALIZER;
va_list ap;
va_start(ap, n_args);
for (size_t i = 0; i < n_args; i++) {
Expand Down Expand Up @@ -20811,7 +20814,7 @@ roaring_bitmap_t *roaring_bitmap_deserialize(const void *buf) {
if (bitmap == NULL) {
return NULL;
}
roaring_bulk_context_t context = {0, 0, 0, 0};
roaring_bulk_context_t context = CROARING_ZERO_INITIALIZER;
for (uint32_t i = 0; i < card; i++) {
// elems may not be aligned, read with memcpy
uint32_t elem;
Expand Down Expand Up @@ -20854,7 +20857,7 @@ roaring_bitmap_t *roaring_bitmap_deserialize_safe(const void *buf,
if (bitmap == NULL) {
return NULL;
}
roaring_bulk_context_t context = {0, 0, 0, 0};
roaring_bulk_context_t context = CROARING_ZERO_INITIALIZER;
for (uint32_t i = 0; i < card; i++) {
// elems may not be aligned, read with memcpy
uint32_t elem;
Expand Down Expand Up @@ -22780,6 +22783,9 @@ roaring64_bitmap_t *roaring64_bitmap_create(void) {
}

void roaring64_bitmap_free(roaring64_bitmap_t *r) {
if (!r) {
return;
}
art_iterator_t it = art_init_iterator(&r->art, /*first=*/true);
while (it.value != NULL) {
leaf_t *leaf = (leaf_t *)it.value;
Expand Down Expand Up @@ -22856,7 +22862,7 @@ 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 = CROARING_ZERO_INITIALIZER;
va_list ap;
va_start(ap, n_args);
for (size_t i = 0; i < n_args; i++) {
Expand Down Expand Up @@ -22949,7 +22955,7 @@ 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 = CROARING_ZERO_INITIALIZER;
for (const uint64_t *current_val = vals; current_val != end;
current_val++) {
roaring64_bitmap_add_bulk(r, &context, *current_val);
Expand Down Expand Up @@ -23273,7 +23279,7 @@ 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 = CROARING_ZERO_INITIALIZER;
for (const uint64_t *current_val = vals; current_val != end;
current_val++) {
roaring64_bitmap_remove_bulk(r, &context, *current_val);
Expand Down Expand Up @@ -23339,6 +23345,10 @@ void roaring64_bitmap_remove_range_closed(roaring64_bitmap_t *r, uint64_t min,
remove_range_closed_at(art, max_high48, 0, max_low16);
}

void roaring64_bitmap_clear(roaring64_bitmap_t *r) {
roaring64_bitmap_remove_range_closed(r, 0, UINT64_MAX);
}

uint64_t roaring64_bitmap_get_cardinality(const roaring64_bitmap_t *r) {
art_iterator_t it = art_init_iterator(&r->art, /*first=*/true);
uint64_t cardinality = 0;
Expand All @@ -23356,7 +23366,17 @@ uint64_t roaring64_bitmap_range_cardinality(const roaring64_bitmap_t *r,
if (min >= max) {
return 0;
}
max--; // A closed range is easier to work with.
// Convert to a closed range
// No underflow here: passing the above condition implies min < max, so
// there is a number less than max
return roaring64_bitmap_range_closed_cardinality(r, min, max - 1);
}

uint64_t roaring64_bitmap_range_closed_cardinality(const roaring64_bitmap_t *r,
uint64_t min, uint64_t max) {
if (min > max) {
return 0;
}

uint64_t cardinality = 0;
uint8_t min_high48[ART_KEY_BYTES];
Expand Down
Loading

0 comments on commit 0d3ff0c

Please sign in to comment.