Skip to content

Commit 0d3ff0c

Browse files
authored
Merge pull request #137 from Dr-Emann/2_0_for_real
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
2 parents bca14a8 + 78c9838 commit 0d3ff0c

File tree

16 files changed

+314
-189
lines changed

16 files changed

+314
-189
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
target
22
.DS_Store
3-
.idea
3+
.idea
4+
README.md.tmp
5+
Cargo.toml.tmp

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test:
1515
croaring_release_url_base = https://github.com/RoaringBitmap/CRoaring/releases/download
1616

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

2020
download_croaring:
2121
rm -f '$(croaring_source)/roaring.c' '$(croaring_source)/roaring.h' '$(croaring_source)/roaring.hh'
@@ -35,6 +35,19 @@ bindgen:
3535
-o bindgen_bundled_version.rs \
3636
roaring.h
3737

38+
39+
# sed -i is a GNU extension, so we use a temporary file explicitly
40+
update_readme_croaring_version:
41+
@echo "Updating README.md with CRoaring version $(version)"
42+
@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
43+
@mv README.md.tmp README.md
44+
45+
# We don't always want to update the version of croaring-sys dependency in croaring, but we always want to update croaring-sys
46+
update_croaring_sys_version:
47+
@echo "Updating croaring-sys version in Cargo.toml to $(version)"
48+
@sed -r -e 's/^version = ".*"/version = "$(version)"/' croaring-sys/Cargo.toml > croaring-sys/Cargo.toml.tmp
49+
@mv croaring-sys/Cargo.toml.tmp croaring-sys/Cargo.toml
50+
3851
# Build a c program to (re)generate the example serialized files for testing
3952
test_serialization_files:
4053
cd croaring/tests/data/ && \

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,10 @@ cargo bench
124124
### Documentation
125125

126126
Current documentation is available at https://docs.rs/croaring/latest/croaring/
127+
128+
## CRoaring Version
129+
130+
This crate uses [CRoaring version `4.1.0`](https://github.com/RoaringBitmap/CRoaring/releases/tag/v4.1.0).
131+
The version of this crate does not necessarily match the version of CRoaring: the major version of the crate is only
132+
incremented when there are breaking changes in the Rust API: It is possible (and has happened) that breaking changes
133+
in the CRoaring C API do not necessitate a major version bump in this crate.

croaring-sys/CRoaring/bindgen_bundled_version.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ pub const ROARING_VERSION_MAJOR: _bindgen_ty_1 = 4;
55
pub const ROARING_VERSION_MINOR: _bindgen_ty_1 = 0;
66
pub const ROARING_VERSION_REVISION: _bindgen_ty_1 = 0;
77
pub type _bindgen_ty_1 = ::core::ffi::c_uint;
8+
extern "C" {
9+
#[doc = " result might be undefined when input_num is zero"]
10+
pub fn roaring_trailing_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
11+
}
12+
extern "C" {
13+
#[doc = " result might be undefined when input_num is zero"]
14+
pub fn roaring_leading_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
15+
}
816
#[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."]
917
#[repr(C)]
1018
#[derive(Debug, Copy, Clone)]
@@ -73,14 +81,6 @@ pub struct roaring_container_iterator_s {
7381
}
7482
#[doc = " Roaring-internal type used to iterate within a roaring container."]
7583
pub type roaring_container_iterator_t = roaring_container_iterator_s;
76-
extern "C" {
77-
#[doc = " result might be undefined when input_num is zero"]
78-
pub fn roaring_trailing_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
79-
}
80-
extern "C" {
81-
#[doc = " result might be undefined when input_num is zero"]
82-
pub fn roaring_leading_zeroes(input_num: ::core::ffi::c_ulonglong) -> ::core::ffi::c_int;
83-
}
8484
#[repr(C)]
8585
#[derive(Debug, Copy, Clone)]
8686
pub struct bitset_s {
@@ -925,6 +925,10 @@ extern "C" {
925925
#[doc = " Remove all values in range [min, max]."]
926926
pub fn roaring64_bitmap_remove_range_closed(r: *mut roaring64_bitmap_t, min: u64, max: u64);
927927
}
928+
extern "C" {
929+
#[doc = " Empties the bitmap."]
930+
pub fn roaring64_bitmap_clear(r: *mut roaring64_bitmap_t);
931+
}
928932
extern "C" {
929933
#[doc = " Returns true if the provided value is present."]
930934
pub fn roaring64_bitmap_contains(r: *const roaring64_bitmap_t, val: u64) -> bool;
@@ -977,6 +981,14 @@ extern "C" {
977981
max: u64,
978982
) -> u64;
979983
}
984+
extern "C" {
985+
#[doc = " Returns the number of elements in the range [min, max]"]
986+
pub fn roaring64_bitmap_range_closed_cardinality(
987+
r: *const roaring64_bitmap_t,
988+
min: u64,
989+
max: u64,
990+
) -> u64;
991+
}
980992
extern "C" {
981993
#[doc = " Returns true if the bitmap is empty (cardinality is zero)."]
982994
pub fn roaring64_bitmap_is_empty(r: *const roaring64_bitmap_t) -> bool;

croaring-sys/CRoaring/roaring.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// !!! DO NOT EDIT - THIS IS AN AUTO-GENERATED FILE !!!
2-
// Created by amalgamation.sh on 2024-05-13T21:29:25Z
2+
// Created by amalgamation.sh on 2024-07-03T21:30:32Z
33

44
/*
55
* The CRoaring project is under a dual license (Apache/MIT).
@@ -10770,7 +10770,7 @@ static bool art_node_iterator_lower_bound(const art_node_t *node,
1077010770
}
1077110771

1077210772
art_iterator_t art_init_iterator(const art_t *art, bool first) {
10773-
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
10773+
art_iterator_t iterator = CROARING_ZERO_INITIALIZER;
1077410774
if (art->root == NULL) {
1077510775
return iterator;
1077610776
}
@@ -10793,8 +10793,11 @@ bool art_iterator_lower_bound(art_iterator_t *iterator,
1079310793
// a valid key. Start from the root.
1079410794
iterator->frame = 0;
1079510795
iterator->depth = 0;
10796-
return art_node_iterator_lower_bound(art_iterator_node(iterator),
10797-
iterator, key);
10796+
art_node_t *root = art_iterator_node(iterator);
10797+
if (root == NULL) {
10798+
return false;
10799+
}
10800+
return art_node_iterator_lower_bound(root, iterator, key);
1079810801
}
1079910802
int compare_result =
1080010803
art_compare_prefix(iterator->key, 0, key, 0, ART_KEY_BYTES);
@@ -10827,15 +10830,15 @@ bool art_iterator_lower_bound(art_iterator_t *iterator,
1082710830
}
1082810831

1082910832
art_iterator_t art_lower_bound(const art_t *art, const art_key_chunk_t *key) {
10830-
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
10833+
art_iterator_t iterator = CROARING_ZERO_INITIALIZER;
1083110834
if (art->root != NULL) {
1083210835
art_node_iterator_lower_bound(art->root, &iterator, key);
1083310836
}
1083410837
return iterator;
1083510838
}
1083610839

1083710840
art_iterator_t art_upper_bound(const art_t *art, const art_key_chunk_t *key) {
10838-
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
10841+
art_iterator_t iterator = CROARING_ZERO_INITIALIZER;
1083910842
if (art->root != NULL) {
1084010843
if (art_node_iterator_lower_bound(art->root, &iterator, key) &&
1084110844
art_compare_keys(iterator.key, key) == 0) {
@@ -19469,7 +19472,7 @@ roaring_bitmap_t *roaring_bitmap_of(size_t n_args, ...) {
1946919472
// todo: could be greatly optimized but we do not expect this call to ever
1947019473
// include long lists
1947119474
roaring_bitmap_t *answer = roaring_bitmap_create();
19472-
roaring_bulk_context_t context = {0, 0, 0, 0};
19475+
roaring_bulk_context_t context = CROARING_ZERO_INITIALIZER;
1947319476
va_list ap;
1947419477
va_start(ap, n_args);
1947519478
for (size_t i = 0; i < n_args; i++) {
@@ -20811,7 +20814,7 @@ roaring_bitmap_t *roaring_bitmap_deserialize(const void *buf) {
2081120814
if (bitmap == NULL) {
2081220815
return NULL;
2081320816
}
20814-
roaring_bulk_context_t context = {0, 0, 0, 0};
20817+
roaring_bulk_context_t context = CROARING_ZERO_INITIALIZER;
2081520818
for (uint32_t i = 0; i < card; i++) {
2081620819
// elems may not be aligned, read with memcpy
2081720820
uint32_t elem;
@@ -20854,7 +20857,7 @@ roaring_bitmap_t *roaring_bitmap_deserialize_safe(const void *buf,
2085420857
if (bitmap == NULL) {
2085520858
return NULL;
2085620859
}
20857-
roaring_bulk_context_t context = {0, 0, 0, 0};
20860+
roaring_bulk_context_t context = CROARING_ZERO_INITIALIZER;
2085820861
for (uint32_t i = 0; i < card; i++) {
2085920862
// elems may not be aligned, read with memcpy
2086020863
uint32_t elem;
@@ -22780,6 +22783,9 @@ roaring64_bitmap_t *roaring64_bitmap_create(void) {
2278022783
}
2278122784

2278222785
void roaring64_bitmap_free(roaring64_bitmap_t *r) {
22786+
if (!r) {
22787+
return;
22788+
}
2278322789
art_iterator_t it = art_init_iterator(&r->art, /*first=*/true);
2278422790
while (it.value != NULL) {
2278522791
leaf_t *leaf = (leaf_t *)it.value;
@@ -22856,7 +22862,7 @@ roaring64_bitmap_t *roaring64_bitmap_of_ptr(size_t n_args,
2285622862

2285722863
roaring64_bitmap_t *roaring64_bitmap_of(size_t n_args, ...) {
2285822864
roaring64_bitmap_t *r = roaring64_bitmap_create();
22859-
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
22865+
roaring64_bulk_context_t context = CROARING_ZERO_INITIALIZER;
2286022866
va_list ap;
2286122867
va_start(ap, n_args);
2286222868
for (size_t i = 0; i < n_args; i++) {
@@ -22949,7 +22955,7 @@ void roaring64_bitmap_add_many(roaring64_bitmap_t *r, size_t n_args,
2294922955
return;
2295022956
}
2295122957
const uint64_t *end = vals + n_args;
22952-
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
22958+
roaring64_bulk_context_t context = CROARING_ZERO_INITIALIZER;
2295322959
for (const uint64_t *current_val = vals; current_val != end;
2295422960
current_val++) {
2295522961
roaring64_bitmap_add_bulk(r, &context, *current_val);
@@ -23273,7 +23279,7 @@ void roaring64_bitmap_remove_many(roaring64_bitmap_t *r, size_t n_args,
2327323279
return;
2327423280
}
2327523281
const uint64_t *end = vals + n_args;
23276-
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
23282+
roaring64_bulk_context_t context = CROARING_ZERO_INITIALIZER;
2327723283
for (const uint64_t *current_val = vals; current_val != end;
2327823284
current_val++) {
2327923285
roaring64_bitmap_remove_bulk(r, &context, *current_val);
@@ -23339,6 +23345,10 @@ void roaring64_bitmap_remove_range_closed(roaring64_bitmap_t *r, uint64_t min,
2333923345
remove_range_closed_at(art, max_high48, 0, max_low16);
2334023346
}
2334123347

23348+
void roaring64_bitmap_clear(roaring64_bitmap_t *r) {
23349+
roaring64_bitmap_remove_range_closed(r, 0, UINT64_MAX);
23350+
}
23351+
2334223352
uint64_t roaring64_bitmap_get_cardinality(const roaring64_bitmap_t *r) {
2334323353
art_iterator_t it = art_init_iterator(&r->art, /*first=*/true);
2334423354
uint64_t cardinality = 0;
@@ -23356,7 +23366,17 @@ uint64_t roaring64_bitmap_range_cardinality(const roaring64_bitmap_t *r,
2335623366
if (min >= max) {
2335723367
return 0;
2335823368
}
23359-
max--; // A closed range is easier to work with.
23369+
// Convert to a closed range
23370+
// No underflow here: passing the above condition implies min < max, so
23371+
// there is a number less than max
23372+
return roaring64_bitmap_range_closed_cardinality(r, min, max - 1);
23373+
}
23374+
23375+
uint64_t roaring64_bitmap_range_closed_cardinality(const roaring64_bitmap_t *r,
23376+
uint64_t min, uint64_t max) {
23377+
if (min > max) {
23378+
return 0;
23379+
}
2336023380

2336123381
uint64_t cardinality = 0;
2336223382
uint8_t min_high48[ART_KEY_BYTES];

0 commit comments

Comments
 (0)