Skip to content

Commit

Permalink
wip: bindings to roaring64 bitmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Emann committed Jan 10, 2024
1 parent b01b9ce commit 1ce614d
Show file tree
Hide file tree
Showing 13 changed files with 9,015 additions and 3,551 deletions.
300 changes: 297 additions & 3 deletions croaring-sys/CRoaring/bindgen_bundled_version.rs

Large diffs are not rendered by default.

10,348 changes: 6,810 additions & 3,538 deletions croaring-sys/CRoaring/roaring.c

Large diffs are not rendered by default.

411 changes: 406 additions & 5 deletions croaring-sys/CRoaring/roaring.h

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion croaring-sys/CRoaring/roaring.hh
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 2023-09-27T16:30:23Z
// Created by amalgamation.sh on 2024-01-09T21:29:32Z

/*
* The CRoaring project is under a dual license (Apache/MIT).
Expand Down Expand Up @@ -603,6 +603,14 @@ public:
return api::roaring_bitmap_rank(&roaring, x);
}

/**
* Get `rank()` values in bulk. The values in `[begin .. end)` must be in Ascending order.
* possible implementation: for(auto* iter = begin; iter != end; ++iter) *(ans++) = rank(*iter);
*/
void rank_many(const uint32_t* begin, const uint32_t* end, uint64_t* ans) const noexcept {
return api::roaring_bitmap_rank_many(&roaring, begin, end, ans);
}

/**
* Returns the index of x in the set, index start from 0.
* If the set doesn't contain x , this function will return -1.
Expand Down Expand Up @@ -748,6 +756,21 @@ public:
return r;
}

/**
* For advanced users; see roaring_bitmap_portable_deserialize_frozen.
* This function may throw std::runtime_error.
*/
static const Roaring portableDeserializeFrozen(const char* buf) {
const roaring_bitmap_t *s =
api::roaring_bitmap_portable_deserialize_frozen(buf);
if (s == NULL) {
ROARING_TERMINATE("failed to read portable frozen bitmap");
}
Roaring r;
r.roaring = *s;
return r;
}

/**
* For advanced users.
*/
Expand Down Expand Up @@ -2282,6 +2305,26 @@ public:
return result;
}

static const Roaring64Map portableDeserializeFrozen(const char* buf) {
Roaring64Map result;
// get map size
uint64_t map_size;
std::memcpy(&map_size, buf, sizeof(uint64_t));
buf += sizeof(uint64_t);
for (uint64_t lcv = 0; lcv < map_size; lcv++) {
// get map key
uint32_t key;
std::memcpy(&key, buf, sizeof(uint32_t));
buf += sizeof(uint32_t);
// read map value Roaring
Roaring read_var = Roaring::portableDeserializeFrozen(buf);
// forward buffer past the last Roaring bitmap
buf += read_var.getSizeInBytes(true);
result.emplaceOrInsert(key, std::move(read_var));
}
return result;
}

// As with serialized 64-bit bitmaps, 64-bit frozen bitmaps are serialized
// by concatenating one or more Roaring::write output buffers with the
// preceeding map key. Unlike standard bitmap serialization, frozen bitmaps
Expand Down
1 change: 0 additions & 1 deletion croaring-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::env;
use std::path::PathBuf;

fn main() {
println!("cargo:rerun-if-changed=CRoaring");
Expand Down
9 changes: 8 additions & 1 deletion croaring/src/bitmap/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Bitmap {
// (it can be moved safely), and can be freed with `free`, without freeing the underlying
// containers and auxiliary data. Ensure this is still valid every time we update
// the version of croaring.
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 2 && ffi::ROARING_VERSION_MINOR == 0);
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 2 && ffi::ROARING_VERSION_MINOR == 1);
ffi::roaring_free(p.cast::<c_void>());
result
}
Expand Down Expand Up @@ -922,6 +922,13 @@ impl Bitmap {
/// // Exclusive ranges still step from the start, but do not include it
/// let bitmap = Bitmap::from_range_with_step((Bound::Excluded(10), Bound::Included(30)), 10);
/// assert_eq!(bitmap.to_vec(), [20, 30]);
///
/// // Ranges including max value
/// let bitmap = Bitmap::from_range_with_step((u32::MAX - 1)..=u32::MAX, 1);
/// assert_eq!(bitmap.to_vec(), vec![u32::MAX - 1, u32::MAX]);
///
/// let bitmap = Bitmap::from_range_with_step((u32::MAX - 1)..=u32::MAX, 3);
/// assert_eq!(bitmap.to_vec(), vec![u32::MAX - 1]);
/// ```
#[inline]
#[doc(alias = "roaring_bitmap_from_range")]
Expand Down
2 changes: 1 addition & 1 deletion croaring/src/bitmap/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Drop for Bitmap {
fn drop(&mut self) {
// This depends somewhat heavily on the implementation of croaring,
// Ensure this is still valid every time we update the version of croaring.
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 2 && ffi::ROARING_VERSION_MINOR == 0);
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 2 && ffi::ROARING_VERSION_MINOR == 1);

// Per https://github.com/RoaringBitmap/CRoaring/blob/4f8dbdb0cc884626b20ef0cc9e891f701fe157cf/cpp/roaring.hh#L182
// > By contract, calling roaring_bitmap_clear() is enough to
Expand Down
2 changes: 1 addition & 1 deletion croaring/src/bitmap/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> BitmapView<'a> {
// `containers` array is stored immediately after the roaring_bitmap_t data.
// Ensure this is still valid every time we update
// the version of croaring.
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 2 && ffi::ROARING_VERSION_MINOR == 0);
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 2 && ffi::ROARING_VERSION_MINOR == 1);

assert!(!p.is_null());

Expand Down
Loading

0 comments on commit 1ce614d

Please sign in to comment.