Skip to content

Commit

Permalink
rename the method and add a little bit of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
irevoire committed Oct 9, 2023
1 parent 3cb7dd4 commit 63a1525
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/bitmap/ops_with_serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,25 @@ const SERIAL_COOKIE_NO_RUNCONTAINER: u32 = 12346;
const SERIAL_COOKIE: u16 = 12347;

impl RoaringBitmap {
pub fn union_with_serialized(&mut self, mut reader: impl Read) -> io::Result<()> {
/// Returns the union between a roaring bitmap and a serialized roaring bitmap.
///
/// Example
/// =======
///
/// ```
/// use roaring::RoaringBitmap;
///
/// let mut a = RoaringBitmap::from_sorted_iter(0..3000).unwrap();
/// let b = RoaringBitmap::from_sorted_iter(2000..6000).unwrap();
/// let union = &a | &b;
///
/// let mut b_ser = Vec::new();
/// b.serialize_into(&mut b_ser).unwrap();
/// a.union_with_serialized_unchecked(&*b_ser).unwrap();
///
/// assert_eq!(a, union);
/// ```
pub fn union_with_serialized_unchecked(&mut self, mut reader: impl Read) -> io::Result<()> {
let (size, has_offsets) = {
let cookie = reader.read_u32::<LittleEndian>()?;
if cookie == SERIAL_COOKIE_NO_RUNCONTAINER {
Expand Down Expand Up @@ -122,7 +140,7 @@ mod test {

let mut b_ser = Vec::new();
b.serialize_into(&mut b_ser).unwrap();
a.union_with_serialized(&*b_ser).unwrap();
a.union_with_serialized_unchecked(&*b_ser).unwrap();

prop_assert_eq!(a, union);
}
Expand Down Expand Up @@ -165,7 +183,7 @@ mod test {

let mut b_ser = Vec::new();
b.serialize_into(&mut b_ser).unwrap();
a.union_with_serialized(&*b_ser).unwrap();
a.union_with_serialized_unchecked(&*b_ser).unwrap();

assert_eq!(a, union, "When testing: {a:?} | {b:?}");
}
Expand Down

0 comments on commit 63a1525

Please sign in to comment.