Skip to content

Commit

Permalink
chore: update bindings to CRoaring 4.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Emann committed Oct 18, 2024
1 parent 96fa650 commit 2c199eb
Show file tree
Hide file tree
Showing 6 changed files with 310 additions and 153 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Current documentation is available at https://docs.rs/croaring/latest/croaring/

## CRoaring Version

This crate uses [CRoaring version `4.1.6`](https://github.com/RoaringBitmap/CRoaring/releases/tag/v4.1.6).
This crate uses [CRoaring version `4.2.1`](https://github.com/RoaringBitmap/CRoaring/releases/tag/v4.2.1).
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.
41 changes: 38 additions & 3 deletions croaring-sys/CRoaring/bindgen_bundled_version.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* automatically generated by rust-bindgen 0.70.1 */

pub const ROARING_VERSION: &[u8; 6] = b"4.1.6\0";
pub const ROARING_VERSION: &[u8; 6] = b"4.2.1\0";
pub const ROARING_VERSION_MAJOR: _bindgen_ty_1 = 4;
pub const ROARING_VERSION_MINOR: _bindgen_ty_1 = 1;
pub const ROARING_VERSION_REVISION: _bindgen_ty_1 = 6;
pub const ROARING_VERSION_MINOR: _bindgen_ty_1 = 2;
pub const ROARING_VERSION_REVISION: _bindgen_ty_1 = 1;
pub type _bindgen_ty_1 = ::core::ffi::c_uint;
extern "C" {
#[doc = " result might be undefined when input_num is zero"]
Expand Down Expand Up @@ -143,6 +143,9 @@ extern "C" {
extern "C" {
pub fn bitset_count(bitset: *const bitset_t) -> usize;
}
extern "C" {
pub fn bitset_empty(bitset: *const bitset_t) -> bool;
}
extern "C" {
pub fn bitset_minimum(bitset: *const bitset_t) -> usize;
}
Expand Down Expand Up @@ -458,6 +461,14 @@ extern "C" {
range_end: u64,
) -> bool;
}
extern "C" {
#[doc = " Check whether a range of values from range_start (included)\n to range_end (included) is present"]
pub fn roaring_bitmap_contains_range_closed(
r: *const roaring_bitmap_t,
range_start: u32,
range_end: u32,
) -> bool;
}
extern "C" {
#[doc = " Check if an items is present, using context from a previous insert or search\n for speed optimization.\n\n `context` will be used to store information between calls to make bulk\n operations faster. `*context` should be zero-initialized before the first\n call to this function.\n\n Modifying the bitmap in any way (other than `-bulk` suffixed functions)\n will invalidate the stored context, calling this function with a non-zero\n context after doing any modification invokes undefined behavior.\n\n In order to exploit this optimization, the caller should call this function\n with values with the same \"key\" (high 16 bits of the value) consecutively."]
pub fn roaring_bitmap_contains_bulk(
Expand All @@ -478,6 +489,14 @@ extern "C" {
range_end: u64,
) -> u64;
}
extern "C" {
#[doc = " Returns the number of elements in the range [range_start, range_end]."]
pub fn roaring_bitmap_range_cardinality_closed(
r: *const roaring_bitmap_t,
range_start: u32,
range_end: u32,
) -> u64;
}
extern "C" {
#[doc = " Returns true if the bitmap is empty (cardinality is zero)."]
pub fn roaring_bitmap_is_empty(r: *const roaring_bitmap_t) -> bool;
Expand Down Expand Up @@ -665,10 +684,26 @@ extern "C" {
range_end: u64,
) -> *mut roaring_bitmap_t;
}
extern "C" {
#[doc = " Compute the negation of the bitmap in the interval [range_start, range_end].\n The number of negated values is range_end - range_start + 1.\n Areas outside the range are passed through unchanged."]
pub fn roaring_bitmap_flip_closed(
x1: *const roaring_bitmap_t,
range_start: u32,
range_end: u32,
) -> *mut roaring_bitmap_t;
}
extern "C" {
#[doc = " compute (in place) the negation of the roaring bitmap within a specified\n interval: [range_start, range_end). The number of negated values is\n range_end - range_start.\n Areas outside the range are passed through unchanged."]
pub fn roaring_bitmap_flip_inplace(r1: *mut roaring_bitmap_t, range_start: u64, range_end: u64);
}
extern "C" {
#[doc = " compute (in place) the negation of the roaring bitmap within a specified\n interval: [range_start, range_end]. The number of negated values is\n range_end - range_start + 1.\n Areas outside the range are passed through unchanged."]
pub fn roaring_bitmap_flip_inplace_closed(
r1: *mut roaring_bitmap_t,
range_start: u32,
range_end: u32,
);
}
extern "C" {
#[doc = " Selects the element at index 'rank' where the smallest element is at index 0.\n If the size of the roaring bitmap is strictly greater than rank, then this\n function returns true and sets element to the element of given rank.\n Otherwise, it returns false."]
pub fn roaring_bitmap_select(r: *const roaring_bitmap_t, rank: u32, element: *mut u32) -> bool;
Expand Down
98 changes: 71 additions & 27 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-09-20T14:21:41Z
// Created by amalgamation.sh on 2024-10-04T22:14:33Z

/*
* The CRoaring project is under a dual license (Apache/MIT).
Expand Down Expand Up @@ -11215,14 +11215,23 @@ bool bitset_inplace_union(bitset_t *CROARING_CBITSET_RESTRICT b1,
return true;
}

bool bitset_empty(const bitset_t *bitset) {
for (size_t k = 0; k < bitset->arraysize; k++) {
if (bitset->array[k] != 0) {
return false;
}
}
return true;
}

size_t bitset_minimum(const bitset_t *bitset) {
for (size_t k = 0; k < bitset->arraysize; k++) {
uint64_t w = bitset->array[k];
if (w != 0) {
return roaring_trailing_zeroes(w) + k * 64;
}
}
return 0;
return SIZE_MAX;
}

bool bitset_grow(bitset_t *bitset, size_t newarraysize) {
Expand Down Expand Up @@ -14097,7 +14106,7 @@ int bitset_container_##opname##_nocard(const bitset_container_t *src_1, \
} \
int bitset_container_##opname##_justcard(const bitset_container_t *src_1, \
const bitset_container_t *src_2) { \
printf("A1\n"); const uint64_t * __restrict__ words_1 = src_1->words; \
const uint64_t * __restrict__ words_1 = src_1->words; \
const uint64_t * __restrict__ words_2 = src_2->words; \
int32_t sum = 0; \
for (size_t i = 0; i < BITSET_CONTAINER_SIZE_IN_WORDS; i += 2) { \
Expand Down Expand Up @@ -19319,6 +19328,7 @@ void roaring_aligned_free(void* p) { global_memory_hook.aligned_free(p); }
/* begin file src/roaring.c */
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -20644,15 +20654,22 @@ uint64_t roaring_bitmap_get_cardinality(const roaring_bitmap_t *r) {
uint64_t roaring_bitmap_range_cardinality(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) {
return 0;
}
return roaring_bitmap_range_cardinality_closed(r, (uint32_t)range_start,
(uint32_t)(range_end - 1));
}

uint64_t roaring_bitmap_range_cardinality_closed(const roaring_bitmap_t *r,
uint32_t range_start,
uint32_t range_end) {
const roaring_array_t *ra = &r->high_low_container;

if (range_end > UINT32_MAX) {
range_end = UINT32_MAX + UINT64_C(1);
}
if (range_start >= range_end) {
if (range_start > range_end) {
return 0;
}
range_end--; // make range_end inclusive

// now we have: 0 <= range_start <= range_end <= UINT32_MAX

uint16_t minhb = (uint16_t)(range_start >> 16);
Expand Down Expand Up @@ -21319,20 +21336,27 @@ 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) {
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1) {
return roaring_bitmap_copy(x1);
}
if (range_end >= UINT64_C(0x100000000)) {
range_end = UINT64_C(0x100000000);
return roaring_bitmap_flip_closed(x1, (uint32_t)range_start,
(uint32_t)(range_end - 1));
}

roaring_bitmap_t *roaring_bitmap_flip_closed(const roaring_bitmap_t *x1,
uint32_t range_start,
uint32_t range_end) {
if (range_start > range_end) {
return roaring_bitmap_copy(x1);
}

roaring_bitmap_t *ans = roaring_bitmap_create();
roaring_bitmap_set_copy_on_write(ans, is_cow(x1));

uint16_t hb_start = (uint16_t)(range_start >> 16);
const uint16_t lb_start = (uint16_t)range_start; // & 0xFFFF;
uint16_t hb_end = (uint16_t)((range_end - 1) >> 16);
const uint16_t lb_end = (uint16_t)(range_end - 1); // & 0xFFFF;
uint16_t hb_end = (uint16_t)(range_end >> 16);
const uint16_t lb_end = (uint16_t)range_end; // & 0xFFFF;

ra_append_copies_until(&ans->high_low_container, &x1->high_low_container,
hb_start, is_cow(x1));
Expand Down Expand Up @@ -21373,17 +21397,24 @@ roaring_bitmap_t *roaring_bitmap_flip(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) {
return; // empty range
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1) {
return;
}
if (range_end >= UINT64_C(0x100000000)) {
range_end = UINT64_C(0x100000000);
roaring_bitmap_flip_inplace_closed(x1, (uint32_t)range_start,
(uint32_t)(range_end - 1));
}

void roaring_bitmap_flip_inplace_closed(roaring_bitmap_t *x1,
uint32_t range_start,
uint32_t range_end) {
if (range_start > range_end) {
return; // empty range
}

uint16_t hb_start = (uint16_t)(range_start >> 16);
const uint16_t lb_start = (uint16_t)range_start;
uint16_t hb_end = (uint16_t)((range_end - 1) >> 16);
const uint16_t lb_end = (uint16_t)(range_end - 1);
uint16_t hb_end = (uint16_t)(range_end >> 16);
const uint16_t lb_end = (uint16_t)range_end;

if (hb_start == hb_end) {
inplace_flip_container(&x1->high_low_container, hb_start, lb_start,
Expand Down Expand Up @@ -22141,15 +22172,28 @@ 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_end >= UINT64_C(0x100000000)) {
range_end = UINT64_C(0x100000000);
if (range_start >= range_end || range_start > (uint64_t)UINT32_MAX + 1) {
return true;
}
if (range_start >= range_end)
return true; // empty range are always contained!
if (range_end - range_start == 1)
return roaring_bitmap_contains_range_closed(r, (uint32_t)range_start,
(uint32_t)(range_end - 1));
}

/**
* Check whether a range of values from range_start (included) to range_end
* (included) is present
*/
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) {
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 - 1) >> 16);
uint16_t hb_re = (uint16_t)(range_end >> 16);
const int32_t span = hb_re - hb_rs;
const int32_t hlc_sz = ra_get_size(&r->high_low_container);
if (hlc_sz < span + 1) {
Expand All @@ -22161,7 +22205,7 @@ bool roaring_bitmap_contains_range(const roaring_bitmap_t *r,
return false;
}
const uint32_t lb_rs = range_start & 0xFFFF;
const uint32_t lb_re = ((range_end - 1) & 0xFFFF) + 1;
const uint32_t lb_re = (range_end & 0xFFFF) + 1;
uint8_t type;
container_t *c =
ra_get_container_at_index(&r->high_low_container, (uint16_t)is, &type);
Expand Down Expand Up @@ -25512,7 +25556,7 @@ size_t ra_portable_deserialize_size(const char *buf, const size_t maxbytes) {
memcpy(&size, buf, sizeof(int32_t));
buf += sizeof(uint32_t);
}
if (size > (1 << 16)) {
if (size > (1 << 16) || size < 0) {
return 0;
}
char *bitmapOfRunContainers = NULL;
Expand Down
53 changes: 46 additions & 7 deletions croaring-sys/CRoaring/roaring.h
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-09-20T14:21:41Z
// Created by amalgamation.sh on 2024-10-04T22:14:33Z

/*
* The CRoaring project is under a dual license (Apache/MIT).
Expand Down Expand Up @@ -59,11 +59,11 @@
// /include/roaring/roaring_version.h automatically generated by release.py, do not change by hand
#ifndef ROARING_INCLUDE_ROARING_VERSION
#define ROARING_INCLUDE_ROARING_VERSION
#define ROARING_VERSION "4.1.6"
#define ROARING_VERSION "4.2.1"
enum {
ROARING_VERSION_MAJOR = 4,
ROARING_VERSION_MINOR = 1,
ROARING_VERSION_REVISION = 6
ROARING_VERSION_MINOR = 2,
ROARING_VERSION_REVISION = 1
};
#endif // ROARING_INCLUDE_ROARING_VERSION
// clang-format on/* end file include/roaring/roaring_version.h */
Expand Down Expand Up @@ -967,7 +967,10 @@ inline bool bitset_get(const bitset_t *bitset, size_t i) {
/* Count number of bits set. */
size_t bitset_count(const bitset_t *bitset);

/* Find the index of the first bit set. Or zero if the bitset is empty. */
/* Returns true if no bit is set. */
bool bitset_empty(const bitset_t *bitset);

/* Find the index of the first bit set. Or SIZE_MAX if the bitset is empty. */
size_t bitset_minimum(const bitset_t *bitset);

/* Find the index of the last bit set. Or zero if the bitset is empty. */
Expand Down Expand Up @@ -1514,7 +1517,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) return;
if (max <= min || min > (uint64_t)UINT32_MAX + 1) {
return;
}
roaring_bitmap_add_range_closed(r, (uint32_t)min, (uint32_t)(max - 1));
}

Expand All @@ -1534,7 +1539,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) return;
if (max <= min || min > (uint64_t)UINT32_MAX + 1) {
return;
}
roaring_bitmap_remove_range_closed(r, (uint32_t)min, (uint32_t)(max - 1));
}

Expand Down Expand Up @@ -1562,6 +1569,14 @@ 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);

/**
* Check whether a range of values from range_start (included)
* to range_end (included) is present
*/
bool roaring_bitmap_contains_range_closed(const roaring_bitmap_t *r,
uint32_t range_start,
uint32_t range_end);

/**
* Check if an items is present, using context from a previous insert or search
* for speed optimization.
Expand Down Expand Up @@ -1593,6 +1608,12 @@ uint64_t roaring_bitmap_range_cardinality(const roaring_bitmap_t *r,
uint64_t range_start,
uint64_t range_end);

/**
* Returns the number of elements in the range [range_start, range_end].
*/
uint64_t roaring_bitmap_range_cardinality_closed(const roaring_bitmap_t *r,
uint32_t range_start,
uint32_t range_end);
/**
* Returns true if the bitmap is empty (cardinality is zero).
*/
Expand Down Expand Up @@ -1994,6 +2015,14 @@ void roaring_bitmap_lazy_xor_inplace(roaring_bitmap_t *r1,
roaring_bitmap_t *roaring_bitmap_flip(const roaring_bitmap_t *r1,
uint64_t range_start, uint64_t range_end);

/**
* Compute the negation of the bitmap in the interval [range_start, range_end].
* The number of negated values is range_end - range_start + 1.
* Areas outside the range are passed through unchanged.
*/
roaring_bitmap_t *roaring_bitmap_flip_closed(const roaring_bitmap_t *x1,
uint32_t range_start,
uint32_t range_end);
/**
* compute (in place) the negation of the roaring bitmap within a specified
* interval: [range_start, range_end). The number of negated values is
Expand All @@ -2003,6 +2032,16 @@ roaring_bitmap_t *roaring_bitmap_flip(const roaring_bitmap_t *r1,
void roaring_bitmap_flip_inplace(roaring_bitmap_t *r1, uint64_t range_start,
uint64_t range_end);

/**
* compute (in place) the negation of the roaring bitmap within a specified
* interval: [range_start, range_end]. The number of negated values is
* range_end - range_start + 1.
* Areas outside the range are passed through unchanged.
*/
void roaring_bitmap_flip_inplace_closed(roaring_bitmap_t *r1,
uint32_t range_start,
uint32_t range_end);

/**
* Selects the element at index 'rank' where the smallest element is at index 0.
* If the size of the roaring bitmap is strictly greater than rank, then this
Expand Down
Loading

0 comments on commit 2c199eb

Please sign in to comment.