Struct vortex_roaring::Bitmap

pub struct Bitmap { /* private fields */ }
Expand description

A compressed bitmap

Implementations§

§

impl Bitmap

pub fn new() -> Bitmap

Creates a new bitmap (initially empty)

§Examples
use croaring::Bitmap;

let bitmap = Bitmap::new();

assert!(bitmap.is_empty());

pub fn with_container_capacity(capacity: u32) -> Bitmap

Creates a new bitmap (initially empty) with a provided container-storage capacity (it is a performance hint).

Note that this is in units of containers, not values: each container holds up to 2^16 values.

§Examples
use croaring::Bitmap;

let bitmap = Bitmap::with_container_capacity(1_000);

assert!(bitmap.is_empty());

pub fn add_many(&mut self, elements: &[u32])

Add the integer element to the bitmap

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.add_many(&[1, 2, 3]);

assert!(!bitmap.is_empty());
assert!(bitmap.contains(1));
assert!(bitmap.contains(2));
assert!(bitmap.contains(3));

pub fn add(&mut self, element: u32)

Add the integer element to the bitmap

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
assert!(bitmap.is_empty());
bitmap.add(1);
assert!(!bitmap.is_empty());

pub fn add_checked(&mut self, element: u32) -> bool

Add the integer element to the bitmap. Returns true if the value was added, false if the value was already in the bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
assert!(bitmap.add_checked(1));
assert!(!bitmap.add_checked(1));

pub fn add_range<R>(&mut self, range: R)
where R: RangeBounds<u32>,

Add all values in range

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::new();
bitmap1.add_range((1..3));

assert!(!bitmap1.is_empty());
assert!(bitmap1.contains(1));
assert!(bitmap1.contains(2));
assert!(!bitmap1.contains(3));

let mut bitmap2 = Bitmap::new();
bitmap2.add_range((3..1));
assert!(bitmap2.is_empty());

let mut bitmap3 = Bitmap::new();
bitmap3.add_range((3..3));
assert!(bitmap3.is_empty());

let mut bitmap4 = Bitmap::new();
bitmap4.add_range(..=2);
bitmap4.add_range(u32::MAX..=u32::MAX);
assert!(bitmap4.contains(0));
assert!(bitmap4.contains(1));
assert!(bitmap4.contains(2));
assert!(bitmap4.contains(u32::MAX));
assert_eq!(bitmap4.cardinality(), 4);

pub fn remove_range<R>(&mut self, range: R)
where R: RangeBounds<u32>,

Remove all values in range

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.add_range((1..4));
assert!(!bitmap.is_empty());

bitmap.remove_range((1..3));

assert!(!bitmap.contains(1));
assert!(!bitmap.contains(2));
assert!(bitmap.contains(3));

bitmap.add_range(u32::MAX..=u32::MAX);
assert!(bitmap.contains(u32::MAX));

pub fn contains_range<R>(&self, range: R) -> bool
where R: RangeBounds<u32>,

Check whether a range of values of range are present

§Examples
use croaring::Bitmap;

let bitmap = Bitmap::of(&[1, 2]);
assert!(bitmap.contains_range((1..3)));

let mut bitmap = bitmap.clone();
bitmap.add(u32::MAX - 1);
bitmap.add(u32::MAX);
assert!(bitmap.contains_range((u32::MAX - 1)..=u32::MAX))

pub fn clear(&mut self)

Empties the bitmap

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.add(1);
bitmap.add(2);
bitmap.clear();

assert!(bitmap.is_empty());

pub fn remove(&mut self, element: u32)

Clear the integer element from the bitmap

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.add(1);
bitmap.remove(1);

assert!(bitmap.is_empty());

pub fn remove_checked(&mut self, element: u32) -> bool

Remove the integer element from the bitmap. Returns true if a the value was removed, false if the value was present in the bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.add(1);
assert!(bitmap.remove_checked(1));
assert!(!bitmap.remove_checked(1));

pub fn remove_many(&mut self, elements: &[u32])

Remove many values from the bitmap

This should be faster than calling remove multiple times.

In order to exploit this optimization, the caller should attempt to keep values with the same high 48 bits of the value as consecutive elements in vals

§Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::of(&[1, 2, 3, 4, 5, 6, 7, 8, 9]);
bitmap.remove_many(&[1, 2, 3, 4, 5, 6, 7, 8]);
assert_eq!(bitmap.iter().collect::<Vec<_>>(), vec![9]);

pub fn contains(&self, element: u32) -> bool

Contains returns true if the integer element is contained in the bitmap

§Examples
use croaring::Bitmap;

let bitmap = Bitmap::of(&[1]);

assert!(bitmap.contains(1));
assert!(!bitmap.contains(2));

pub fn add_offset(&self, offset: i64) -> Bitmap

Compute a new bitmap, which contains all values from this bitmap, but shifted by offset

Any values which would be < 0, or > u32::MAX are dropped.

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[0, 1, 1000, u32::MAX]);
let shifted_down = bitmap1.add_offset(-1);
assert_eq!(shifted_down.iter().collect::<Vec<_>>(), [0, 999, u32::MAX - 1]);
let shifted_up = bitmap1.add_offset(1);
assert_eq!(shifted_up.iter().collect::<Vec<_>>(), [1, 2, 1001]);
let big_shifted = bitmap1.add_offset(i64::from(u32::MAX) + 1);
assert_eq!(big_shifted.iter().collect::<Vec<_>>(), []);

pub fn range_cardinality<R>(&self, range: R) -> u64
where R: RangeBounds<u32>,

Returns number of elements in range

§Examples
use croaring::Bitmap;

let bitmap = Bitmap::of(&[1, 3, 4]);

assert_eq!(bitmap.range_cardinality((..1)), 0);
assert_eq!(bitmap.range_cardinality((..2)), 1);
assert_eq!(bitmap.range_cardinality((2..5)), 2);
assert_eq!(bitmap.range_cardinality((..5)), 3);
assert_eq!(bitmap.range_cardinality((1..=4)), 3);

pub fn cardinality(&self) -> u64

Returns the number of integers contained in the bitmap

§Examples
use croaring::Bitmap;

let bitmap = Bitmap::of(&[1]);

assert_eq!(bitmap.cardinality(), 1);

let mut bitmap = bitmap.clone();

bitmap.add(2);

assert_eq!(bitmap.cardinality(), 2);

pub fn and(&self, other: &Bitmap) -> Bitmap

And computes the intersection between two bitmaps and returns the result as a new bitmap

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[1]);
let bitmap2 = Bitmap::of(&[1, 2]);

let bitmap3 = bitmap1.and(&bitmap2);

assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));

pub fn and_inplace(&mut self, other: &Bitmap)

Computes the intersection between two bitmaps and stores the result in the current bitmap

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);
let mut bitmap3 = Bitmap::of(&[15]);
let bitmap4 = Bitmap::of(&[15, 25]);

bitmap1.and_inplace(&bitmap2);

assert_eq!(bitmap1.cardinality(), 0);
assert!(!bitmap1.contains(15));
assert!(!bitmap1.contains(25));

bitmap3.and_inplace(&bitmap4);

assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));

pub fn or(&self, other: &Bitmap) -> Bitmap

Or computes the union between two bitmaps and returns the result as a new bitmap

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

let bitmap3 = bitmap1.or(&bitmap2);

assert_eq!(bitmap3.cardinality(), 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));

pub fn or_inplace(&mut self, other: &Bitmap)

Computes the union between two bitmaps and stores the result in the current bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

bitmap1.or_inplace(&bitmap2);

assert_eq!(bitmap1.cardinality(), 2);
assert!(bitmap1.contains(15));
assert!(bitmap1.contains(25));

pub fn fast_or(bitmaps: &[&Bitmap]) -> Bitmap

Computes the union between many bitmaps quickly, as opposed to having to call or() repeatedly. Returns the result as a new bitmap.

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);
let bitmap3 = Bitmap::of(&[35]);

let bitmap4 = Bitmap::fast_or(&[&bitmap1, &bitmap2, &bitmap3]);

assert_eq!(bitmap4.cardinality(), 3);
assert!(bitmap4.contains(15));
assert!(bitmap4.contains(25));
assert!(bitmap4.contains(25));

pub fn fast_or_heap(bitmaps: &[&Bitmap]) -> Bitmap

Compute the union of ‘number’ bitmaps using a heap. This can sometimes be faster than Bitmap::fast_or.

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);
let bitmap3 = Bitmap::of(&[35]);

let bitmap4 = Bitmap::fast_or_heap(&[&bitmap1, &bitmap2, &bitmap3]);

assert_eq!(bitmap4.cardinality(), 3);
assert!(bitmap4.contains(15));
assert!(bitmap4.contains(25));
assert!(bitmap4.contains(25));

pub fn xor(&self, other: &Bitmap) -> Bitmap

Computes the symmetric difference (xor) between two bitmaps and returns new bitmap.

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1.xor(&bitmap2);

assert_eq!(bitmap3.cardinality(), 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));

pub fn xor_inplace(&mut self, other: &Bitmap)

Inplace version of roaring_bitmap_xor, stores result in current bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1.xor_inplace(&bitmap2);

assert_eq!(bitmap1.cardinality(), 2);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(bitmap1.contains(35));

pub fn fast_xor(bitmaps: &[&Bitmap]) -> Bitmap

Computes the symmetric difference (xor) between multiple bitmaps and returns new bitmap as a result.

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = Bitmap::fast_xor(&[&bitmap1, &bitmap2]);

assert_eq!(bitmap3.cardinality(), 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));

pub fn andnot(&self, other: &Bitmap) -> Bitmap

Computes the difference between two bitmaps and returns the result.

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1.andnot(&bitmap2);

assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));

pub fn andnot_inplace(&mut self, other: &Bitmap)

Computes the difference between two bitmaps and stores the result in the current bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1.andnot_inplace(&bitmap2);

assert_eq!(bitmap1.cardinality(), 1);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(!bitmap1.contains(35));

let mut bitmap3 = Bitmap::of(&[15]);
let bitmap4 = Bitmap::new();
bitmap3.andnot_inplace(&bitmap4);
assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));

pub fn flip<R>(&self, range: R) -> Bitmap
where R: RangeBounds<u32>,

Negates the bits in the given range any integer present in this range and in the bitmap is removed. Returns result as a new bitmap.

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[4]);

let bitmap2 = bitmap1.flip(1..3);

assert_eq!(bitmap2.cardinality(), 3);
assert!(bitmap2.contains(1));
assert!(bitmap2.contains(2));
assert!(!bitmap2.contains(3));
assert!(bitmap2.contains(4));

let bitmap3 = bitmap1.flip(1..=5);
assert_eq!(bitmap3.iter().collect::<Vec<_>>(), [1, 2, 3, 5])

pub fn flip_inplace<R>(&mut self, range: R)
where R: RangeBounds<u32>,

Negates the bits in the given range any integer present in this range and in the bitmap is removed. Stores the result in the current bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[4]);
bitmap1.flip_inplace(1..3);

assert_eq!(bitmap1.cardinality(), 3);
assert!(bitmap1.contains(1));
assert!(bitmap1.contains(2));
assert!(!bitmap1.contains(3));
assert!(bitmap1.contains(4));
bitmap1.flip_inplace(4..=4);
assert_eq!(bitmap1.iter().collect::<Vec<_>>(), [1, 2]);

pub fn for_each<F, O>(&self, f: F) -> ControlFlow<O>
where F: FnMut(u32) -> ControlFlow<O>,

Iterate over the values in the bitmap in sorted order

If f returns Break, iteration will stop and the value will be returned, Otherwise, iteration continues. If f never returns break, None is returned after all values are visited.

§Examples
use croaring::Bitmap;
use std::ops::ControlFlow;

let bitmap = Bitmap::of(&[1, 2, 3, 14, 20, 21, 100]);
let mut even_nums_under_50 = vec![];

let first_over_50 = bitmap.for_each(|value| {
    if value > 50 {
       return ControlFlow::Break(value);
    }
    if value % 2 == 0 {
        even_nums_under_50.push(value);
    }
    ControlFlow::Continue(())
});

assert_eq!(even_nums_under_50, vec![2, 14, 20]);
assert_eq!(first_over_50, ControlFlow::Break(100));

pub fn to_vec(&self) -> Vec<u32>

Returns a vector containing all of the integers stored in the Bitmap in sorted order.

use croaring::Bitmap;

let bitmap = Bitmap::of(&[15, 25]);

assert_eq!(bitmap.to_vec(), [15, 25]);

pub fn get_serialized_size_in_bytes<S>(&self) -> usize
where S: Serializer,

Computes the serialized size in bytes of the Bitmap in format S.

pub fn serialize<S>(&self) -> Vec<u8>
where S: Serializer + NoAlign,

Serializes a bitmap to a slice of bytes in format S.

This function cannot be used with formats that require alignment, such as [crate::Frozen].

§Examples
use croaring::{Bitmap, Portable};

let original_bitmap: Bitmap = (1..5).collect();

let serialized_buffer = original_bitmap.serialize::<Portable>();

let deserialized_bitmap = Bitmap::deserialize::<Portable>(&serialized_buffer);

assert_eq!(original_bitmap, deserialized_bitmap);
use croaring::{Bitmap, Frozen};

let original_bitmap = Bitmap::of(&[1, 2, 3]);
// This will not compile, as `Frozen` requires alignment, and we can't guarantee that the
// start of the vec is aligned correctly
let serialized_buffer = original_bitmap.serialize::<Frozen>();

pub fn serialize_into_vec<'a, S>(&self, dst: &'a mut Vec<u8>) -> &'a mut [u8]
where S: Serializer,

Serializes a bitmap to a slice of bytes in format S, re-using existing capacity

dst is not cleared, data is added after any existing data. Returns the added slice of dst. Because of alignment requirements, the serialized data may not start at the beginning of dst: the returned slice may not start at dst.as_ptr().

§Examples
use croaring::{Bitmap, Portable};

let original_bitmap_1: Bitmap = (1..5).collect();
let original_bitmap_2: Bitmap = (1..10).collect();

let mut data = Vec::new();
for bitmap in [original_bitmap_1, original_bitmap_2] {
    data.clear();
    let serialized: &[u8] = bitmap.serialize_into_vec::<Portable>(&mut data);
    // do something with serialized data
}

pub fn try_serialize_into<'a, S>( &self, dst: &'a mut [u8], ) -> Option<&'a mut [u8]>
where S: Serializer,

Serializes a bitmap to a slice of bytes in format S

Returns the serialized data if the buffer was large enough, otherwise None.

See Self::get_serialized_size_in_bytes to determine the required buffer size. Note also that some ([crate::Frozen]) formats require alignment, so the buffer size may need to be larger than the serialized size.

See also Self::serialize_into_vec for a version that uses a Vec instead, or, for advanced use-cases, see [Serializer::try_serialize_into].

pub fn try_deserialize<D>(buffer: &[u8]) -> Option<Bitmap>
where D: Deserializer,

Given a serialized bitmap as slice of bytes in format S, returns a Bitmap instance. See example of Self::serialize function.

On invalid input returns None.

§Examples
use croaring::{Bitmap, Portable};

let original_bitmap: Bitmap = (1..5).collect();
let serialized_buffer = original_bitmap.serialize::<Portable>();

let deserialized_bitmap = Bitmap::try_deserialize::<Portable>(&serialized_buffer);
assert_eq!(original_bitmap, deserialized_bitmap.unwrap());

let invalid_buffer: Vec<u8> = vec![3];
let deserialized_bitmap = Bitmap::try_deserialize::<Portable>(&invalid_buffer);
assert!(deserialized_bitmap.is_none());

pub fn deserialize<D>(buffer: &[u8]) -> Bitmap
where D: Deserializer,

Given a serialized bitmap as slice of bytes in format S , returns a bitmap instance. See example of Self::serialize function.

On invalid input returns empty bitmap.

pub fn of(elements: &[u32]) -> Bitmap

Creates a new bitmap from a slice of u32 integers

§Examples
use croaring::Bitmap;

let elements = vec![1, 2];

let bitmap = Bitmap::of(&elements);

let mut bitmap2 = Bitmap::new();

for element in &elements {
    bitmap2.add(*element);
}

assert!(bitmap.contains(1));
assert!(bitmap.contains(2));
assert!(!bitmap.contains(3));
assert_eq!(bitmap, bitmap2);

pub fn from_range<R>(range: R) -> Bitmap
where R: RangeBounds<u32>,

Create a new bitmap with all values in range

§Examples
use std::ops::Bound;
use croaring::Bitmap;

let bitmap1 = Bitmap::from_range(5..10);
assert_eq!(bitmap1.iter().collect::<Vec<_>>(), [5, 6, 7, 8, 9]);

let bitmap2 = Bitmap::from_range(5..=7);
assert_eq!(bitmap2.iter().collect::<Vec<_>>(), [5, 6, 7]);

let bitmap3 = Bitmap::from_range((Bound::Excluded(2), Bound::Excluded(6)));
assert_eq!(bitmap3.iter().collect::<Vec<_>>(), [3, 4, 5]);

pub fn from_range_with_step<R>(range: R, step: u32) -> Bitmap
where R: RangeBounds<u32>,

Create a new bitmap with all values in range which are a multiple of step away from the lower bound

If step is zero or there are no values which are a multiple of step away from the lower bound within range, an empty bitmap is returned.

§Examples
use std::ops::Bound;
use croaring::Bitmap;

let bitmap = Bitmap::from_range_with_step(0..10, 3);
assert_eq!(bitmap.iter().collect::<Vec<_>>(), [0, 3, 6, 9]);

// empty ranges
assert_eq!(Bitmap::from_range_with_step(0..0, 1), Bitmap::new());
assert_eq!(Bitmap::from_range_with_step(100..=0, 1), Bitmap::new());

// Step of zero
assert_eq!(Bitmap::from_range_with_step(0..100, 0), Bitmap::new());

// No values of step in range
let bitmap = Bitmap::from_range_with_step((Bound::Excluded(0), Bound::Included(10)), 100);
assert_eq!(bitmap, Bitmap::new());
let bitmap = Bitmap::from_range_with_step((Bound::Excluded(u32::MAX), Bound::Included(u32::MAX)), 1);
assert_eq!(bitmap, Bitmap::new());

// 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.iter().collect::<Vec<_>>(), [20, 30]);

// Ranges including max value
let bitmap = Bitmap::from_range_with_step((u32::MAX - 1)..=u32::MAX, 1);
assert_eq!(bitmap.iter().collect::<Vec<_>>(), vec![u32::MAX - 1, u32::MAX]);

let bitmap = Bitmap::from_range_with_step((u32::MAX - 1)..=u32::MAX, 3);
assert_eq!(bitmap.iter().collect::<Vec<_>>(), vec![u32::MAX - 1]);

pub fn shrink_to_fit(&mut self) -> usize

Shrink the memory allocation of the bitmap if needed

Returns the number of bytes saved

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::with_container_capacity(10);
let saved_bytes = bitmap.shrink_to_fit();
assert!(saved_bytes > 0);
let more_saved_bytes = bitmap.shrink_to_fit();
assert_eq!(more_saved_bytes, 0);

pub fn run_optimize(&mut self) -> bool

Compresses of the bitmap. Returns true if the bitmap was modified.

§Examples
use croaring::{Bitmap, Portable};

let mut bitmap: Bitmap = (100..1000).collect();

assert_eq!(bitmap.cardinality(), 900);
let old_size = bitmap.get_serialized_size_in_bytes::<Portable>();
assert!(bitmap.run_optimize());
let new_size = bitmap.get_serialized_size_in_bytes::<Portable>();
assert!(new_size < old_size);

pub fn remove_run_compression(&mut self) -> bool

Removes run-length encoding even when it is more space efficient. Returns true if a change was applied.

§Examples
use croaring::Bitmap;

let mut bitmap: Bitmap = (100..1000).collect();

assert_eq!(bitmap.cardinality(), 900);

bitmap.run_optimize();

assert!(bitmap.remove_run_compression());
assert!(!bitmap.remove_run_compression());

pub fn is_empty(&self) -> bool

Returns true if the Bitmap is empty. Faster than doing: bitmap.cardinality() == 0)

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();

assert!(bitmap.is_empty());

bitmap.add(1);

assert!(!bitmap.is_empty());

pub fn is_subset(&self, other: &Bitmap) -> bool

Return true if all the elements of Self are in &other.

§Examples
use croaring::Bitmap;

let bitmap1: Bitmap = (5..10).collect();
let bitmap2: Bitmap = (5..8).collect();
let bitmap3: Bitmap = (5..10).collect();
let bitmap4: Bitmap = (9..11).collect();

assert!(bitmap2.is_subset(&bitmap1));
assert!(bitmap3.is_subset(&bitmap1));
assert!(!bitmap4.is_subset(&bitmap1));

pub fn is_strict_subset(&self, other: &Bitmap) -> bool

Return true if all the elements of Self are in &other and &other is strictly greater than Self.

§Examples
use croaring::Bitmap;

let bitmap1: Bitmap = (5..9).collect();
let bitmap2: Bitmap = (5..8).collect();
let bitmap3: Bitmap = (5..10).collect();
let bitmap4: Bitmap = (9..11).collect();

assert!(bitmap2.is_subset(&bitmap1));
assert!(!bitmap3.is_subset(&bitmap1));
assert!(!bitmap4.is_subset(&bitmap1));

pub fn intersect(&self, other: &Bitmap) -> bool

Return true if Self and &other intersect

§Examples
use croaring::Bitmap;

let bitmap1: Bitmap = (1..5).collect();
let bitmap2: Bitmap = (5..9).collect();
let bitmap3: Bitmap = (3..7).collect();

assert_eq!(bitmap1.intersect(&bitmap2), false);
assert_eq!(bitmap1.intersect(&bitmap3), true);
assert_eq!(bitmap2.intersect(&bitmap3), true);

pub fn intersect_with_range<R>(&self, range: R) -> bool
where R: RangeBounds<u32>,

Check if a bitmap has any values set in range

§Examples
use croaring::Bitmap;

let bitmap = Bitmap::of(&[1, 100, 101, u32::MAX]);

assert!(bitmap.intersect_with_range(0..10));
assert!(!bitmap.intersect_with_range(2..100));
assert!(bitmap.intersect_with_range(999..=u32::MAX));

// Empty ranges
assert!(!bitmap.intersect_with_range(100..100));
assert!(!bitmap.intersect_with_range(100..0));

pub fn jaccard_index(&self, other: &Bitmap) -> f64

Return the Jaccard index between Self and &other

use croaring::Bitmap;

let bitmap1: Bitmap = (1..5).collect();
let bitmap2: Bitmap = (5..9).collect();
let bitmap3: Bitmap = (3..9).collect();

assert_eq!(bitmap1.jaccard_index(&bitmap2), 0.0);
assert_eq!(bitmap1.jaccard_index(&bitmap3), 0.25);
assert_eq!(bitmap2.jaccard_index(&bitmap3), 0.6666666666666666);

pub fn and_cardinality(&self, other: &Bitmap) -> u64

Return the size of the intersection between Self and &other

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[1]);
let bitmap2 = Bitmap::of(&[1, 2]);

assert_eq!(bitmap1.and_cardinality(&bitmap2), 1);

pub fn or_cardinality(&self, other: &Bitmap) -> u64

Return the size of the union between Self and &other

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

assert_eq!(bitmap1.or_cardinality(&bitmap2), 2);

pub fn andnot_cardinality(&self, other: &Bitmap) -> u64

Return the size of the difference between Self and &other

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

assert_eq!(bitmap1.andnot_cardinality(&bitmap2), 1);

pub fn xor_cardinality(&self, other: &Bitmap) -> u64

Return the size of the symmetric difference between Self and &other

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

assert_eq!(bitmap1.xor_cardinality(&bitmap2), 2);

pub fn minimum(&self) -> Option<u32>

Returns the smallest value in the set.

Returns None if the set is empty.

§Examples
use croaring::Bitmap;

let mut bitmap: Bitmap = (5..10).collect();
let empty_bitmap: Bitmap = Bitmap::new();

assert_eq!(bitmap.minimum(), Some(5));
assert_eq!(empty_bitmap.minimum(), None);

bitmap.add(3);

assert_eq!(bitmap.minimum(), Some(3));

pub fn maximum(&self) -> Option<u32>

Returns the greatest value in the set.

Returns None if the set is empty.

§Examples
use croaring::Bitmap;

let mut bitmap: Bitmap = (5..10).collect();
let empty_bitmap: Bitmap = Bitmap::new();

assert_eq!(bitmap.maximum(), Some(9));
assert_eq!(empty_bitmap.maximum(), None);

bitmap.add(15);

assert_eq!(bitmap.maximum(), Some(15));

pub fn rank(&self, x: u32) -> u64

Rank returns the number of values smaller or equal to x.

For a similar function which also checks if x is in the set, see position.

§Examples
use croaring::Bitmap;

let mut bitmap: Bitmap = (5..10).collect();

assert_eq!(bitmap.rank(8), 4);

bitmap.add(15);

assert_eq!(bitmap.rank(11), 5);
assert_eq!(bitmap.rank(15), 6);

pub fn position(&self, x: u32) -> Option<u32>

Returns the index of x in the given roaring bitmap.

If the roaring bitmap doesn’t contain x, this function will return None. The difference with the rank function is that this function will return None when x is not the element of roaring bitmap, but the rank function will return the the number of items less than x, and would require a call to contains to check if x is in the roaring bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap: Bitmap = Bitmap::from_range(5..10);
assert_eq!(bitmap.position(4), None);
assert_eq!(bitmap.position(5), Some(0));
assert_eq!(bitmap.position(9), Some(4));
assert_eq!(bitmap.position(10), None);
assert_eq!(bitmap.position(9999), None);

// rank returns the number of values smaller or equal to x, so it always returns a value, and
// returns `position + 1` when x is contained in the bitmap.
assert_eq!(bitmap.rank(4), 0);
assert_eq!(bitmap.rank(5), 1);
assert_eq!(bitmap.rank(9), 5);
assert_eq!(bitmap.rank(10), 5);
assert_eq!(bitmap.rank(9999), 5);

let pos = bitmap.position(7).unwrap();
assert_eq!(bitmap.select(pos), Some(7));

pub fn select(&self, position: u32) -> Option<u32>

Select returns the element having the designated position, if it exists

If the size of the roaring bitmap is strictly greater than pos, then this function returns element of given rank wrapped in Some. Otherwise, it returns None.

To do the inverse operation (given an element, find its position), use the position function, or the rank function.

Note that the rank function is inclusive: it returns the number of values smaller or equal to x, when x is contained in the bitmap, it returns position + 1.

§Examples
use croaring::Bitmap;

let bitmap: Bitmap = (5..10).collect();

assert_eq!(bitmap.select(0), Some(5));
assert_eq!(bitmap.select(1), Some(6));
assert_eq!(bitmap.select(2), Some(7));
assert_eq!(bitmap.select(3), Some(8));
assert_eq!(bitmap.select(4), Some(9));
assert_eq!(bitmap.select(5), None);

pub fn statistics(&self) -> Statistics

Returns statistics about the composition of a roaring bitmap.

§Examples
use croaring::Bitmap;

let mut bitmap: Bitmap = (1..100).collect();
let statistics = bitmap.statistics();

assert_eq!(statistics.n_containers, 1);
assert_eq!(statistics.n_array_containers, 1);
assert_eq!(statistics.n_run_containers, 0);
assert_eq!(statistics.n_bitset_containers, 0);
assert_eq!(statistics.n_values_array_containers, 99);
assert_eq!(statistics.n_values_run_containers, 0);
assert_eq!(statistics.n_values_bitset_containers, 0);
assert_eq!(statistics.n_bytes_array_containers, 198);
assert_eq!(statistics.n_bytes_run_containers, 0);
assert_eq!(statistics.n_bytes_bitset_containers, 0);
assert_eq!(statistics.max_value, 99);
assert_eq!(statistics.min_value, 1);
assert_eq!(statistics.cardinality, 99);

bitmap.run_optimize();
let statistics = bitmap.statistics();

assert_eq!(statistics.n_containers, 1);
assert_eq!(statistics.n_array_containers, 0);
assert_eq!(statistics.n_run_containers, 1);
assert_eq!(statistics.n_bitset_containers, 0);
assert_eq!(statistics.n_values_array_containers, 0);
assert_eq!(statistics.n_values_run_containers, 99);
assert_eq!(statistics.n_values_bitset_containers, 0);
assert_eq!(statistics.n_bytes_array_containers, 0);
assert_eq!(statistics.n_bytes_run_containers, 6);
assert_eq!(statistics.n_bytes_bitset_containers, 0);
assert_eq!(statistics.max_value, 99);
assert_eq!(statistics.min_value, 1);
assert_eq!(statistics.cardinality, 99);

pub fn to_bitset(&self) -> Option<Bitset>

Store the bitmap to a bitset

This can be useful for those who need the performance and simplicity of a standard bitset.

§Errors

This function will return None on allocation failure

§Examples
use croaring::Bitmap;
let bitmap = Bitmap::from_range(0..100);
let bitset = bitmap.to_bitset().unwrap();
assert_eq!(bitset.count(), 100);
§

impl Bitmap

pub fn iter(&self) -> BitmapIterator<'_>

Returns an iterator over each value stored in the bitmap. Returned values are ordered in ascending order.

§Examples
use croaring::Bitmap;

let mut bitmap = Bitmap::new();
bitmap.add(4);
bitmap.add(3);
bitmap.add(2);
let mut iterator = bitmap.iter();

assert_eq!(iterator.next(), Some(2));
assert_eq!(iterator.next(), Some(3));
assert_eq!(iterator.next(), Some(4));
assert_eq!(iterator.next(), None);

pub fn cursor(&self) -> BitmapCursor<'_>

Returns a cursor pointing at the first value in the bitmap.

See [BitmapCursor] for more details.

pub fn cursor_to_last(&self) -> BitmapCursor<'_>

Returns a cursor pointing at the last value in the bitmap.

See [BitmapCursor] for more details.

§

impl Bitmap

pub fn lazy_batch<F, O>(&mut self, f: F) -> O
where F: FnOnce(&mut LazyBitmap<'_>) -> O,

Perform multiple bitwise operations on a bitmap.

The passed closure will be passed a handle which can be used to perform bitwise operations on the bitmap lazily.

The result will be equivalent to doing the same operations on this bitmap directly, but because of reduced bookkeeping in between operations, it should be faster

§Examples
use croaring::Bitmap;

// Perform a series of bitwise operations on a bitmap:
let mut bitmap = Bitmap::of(&[99]);
let bitmaps_to_or = [Bitmap::of(&[1, 2, 5, 10]), Bitmap::of(&[1, 30, 100])];
let bitmaps_to_xor = [Bitmap::of(&[5]), Bitmap::of(&[1, 1000, 1001])];

bitmap.lazy_batch(|lazy| {
    for b in &bitmaps_to_or {
        *lazy |= b;
    }
    for b in &bitmaps_to_xor {
        *lazy ^= b;
    }
});
let mut bitmap2 = Bitmap::of(&[99]);
for b in &bitmaps_to_or {
    bitmap2 |= b;
}
for b in &bitmaps_to_xor {
    bitmap2 ^= b;
}
assert_eq!(bitmap, bitmap2);
assert_eq!(bitmap.iter().collect::<Vec<_>>(), [2, 10, 30, 99, 100, 1000, 1001]);

The result the passed closure is returned from lazy_batch

use croaring::Bitmap;

let mut bitmap = Bitmap::new();
let bitmaps_to_or = [Bitmap::of(&[1, 2, 5, 10]), Bitmap::of(&[1, 30, 100])];
let total_added = bitmap.lazy_batch(|lazy| {
    let mut total = 0;
    for b in &bitmaps_to_or {
        lazy.or_inplace(b, true);
        total += b.cardinality();
    }
    total
});
assert_eq!(total_added, 7);

Trait Implementations§

§

impl BitAnd<&Bitmap> for &Bitmap

§

fn bitand(self, other: &Bitmap) -> Bitmap

Syntactic sugar for .and

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::new();
bitmap1.add(1);

let mut bitmap2 = Bitmap::new();
bitmap2.add(1);
bitmap2.add(2);

let bitmap3 = bitmap1 & bitmap2;

assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
§

type Output = Bitmap

The resulting type after applying the & operator.
§

impl BitAnd<&Bitmap> for Bitmap

§

fn bitand(self, other: &Bitmap) -> Bitmap

Syntactic sugar for .and

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::new();
bitmap1.add(1);

let mut bitmap2 = Bitmap::new();
bitmap2.add(1);
bitmap2.add(2);

let bitmap3 = bitmap1 & bitmap2;

assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
§

type Output = Bitmap

The resulting type after applying the & operator.
§

impl BitAnd<Bitmap> for &Bitmap

§

fn bitand(self, other: Bitmap) -> Bitmap

Syntactic sugar for .and

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::new();
bitmap1.add(1);

let mut bitmap2 = Bitmap::new();
bitmap2.add(1);
bitmap2.add(2);

let bitmap3 = bitmap1 & bitmap2;

assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
§

type Output = Bitmap

The resulting type after applying the & operator.
§

impl BitAnd for Bitmap

§

fn bitand(self, other: Bitmap) -> Bitmap

Syntactic sugar for .and

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::new();
bitmap1.add(1);

let mut bitmap2 = Bitmap::new();
bitmap2.add(1);
bitmap2.add(2);

let bitmap3 = bitmap1 & bitmap2;

assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
§

type Output = Bitmap

The resulting type after applying the & operator.
§

impl BitAndAssign<&Bitmap> for Bitmap

§

fn bitand_assign(&mut self, other: &Bitmap)

Syntactic sugar for .and_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);
let mut bitmap3 = Bitmap::of(&[15]);
let bitmap4 = Bitmap::of(&[15, 25]);

bitmap1 &= bitmap2;

assert!(bitmap1.cardinality() == 0);
assert!(!bitmap1.contains(15));
assert!(!bitmap1.contains(25));

bitmap3 &= bitmap4;

assert!(bitmap3.cardinality() == 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
§

impl BitAndAssign<&BitmapView<'_>> for Bitmap

§

fn bitand_assign(&mut self, other: &BitmapView<'_>)

Syntactic sugar for .and_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);
let mut bitmap3 = Bitmap::of(&[15]);
let bitmap4 = Bitmap::of(&[15, 25]);

bitmap1 &= bitmap2;

assert!(bitmap1.cardinality() == 0);
assert!(!bitmap1.contains(15));
assert!(!bitmap1.contains(25));

bitmap3 &= bitmap4;

assert!(bitmap3.cardinality() == 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
§

impl BitAndAssign<BitmapView<'_>> for Bitmap

§

fn bitand_assign(&mut self, other: BitmapView<'_>)

Syntactic sugar for .and_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);
let mut bitmap3 = Bitmap::of(&[15]);
let bitmap4 = Bitmap::of(&[15, 25]);

bitmap1 &= bitmap2;

assert!(bitmap1.cardinality() == 0);
assert!(!bitmap1.contains(15));
assert!(!bitmap1.contains(25));

bitmap3 &= bitmap4;

assert!(bitmap3.cardinality() == 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
§

impl BitAndAssign for Bitmap

§

fn bitand_assign(&mut self, other: Bitmap)

Syntactic sugar for .and_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);
let mut bitmap3 = Bitmap::of(&[15]);
let bitmap4 = Bitmap::of(&[15, 25]);

bitmap1 &= bitmap2;

assert!(bitmap1.cardinality() == 0);
assert!(!bitmap1.contains(15));
assert!(!bitmap1.contains(25));

bitmap3 &= bitmap4;

assert!(bitmap3.cardinality() == 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
§

impl BitOr<&Bitmap> for &Bitmap

§

fn bitor(self, other: &Bitmap) -> Bitmap

Syntatic sugar for .or

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

let bitmap3 = bitmap1 | bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
§

type Output = Bitmap

The resulting type after applying the | operator.
§

impl BitOr<&Bitmap> for Bitmap

§

fn bitor(self, other: &Bitmap) -> Bitmap

Syntatic sugar for .or

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

let bitmap3 = bitmap1 | bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
§

type Output = Bitmap

The resulting type after applying the | operator.
§

impl BitOr<Bitmap> for &Bitmap

§

fn bitor(self, other: Bitmap) -> Bitmap

Syntatic sugar for .or

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

let bitmap3 = bitmap1 | bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
§

type Output = Bitmap

The resulting type after applying the | operator.
§

impl BitOr for Bitmap

§

fn bitor(self, other: Bitmap) -> Bitmap

Syntatic sugar for .or

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

let bitmap3 = bitmap1 | bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
§

type Output = Bitmap

The resulting type after applying the | operator.
§

impl BitOrAssign<&Bitmap> for Bitmap

§

fn bitor_assign(&mut self, other: &Bitmap)

Syntatic sugar for .or_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

bitmap1 |= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(bitmap1.contains(25));
§

impl BitOrAssign<&BitmapView<'_>> for Bitmap

§

fn bitor_assign(&mut self, other: &BitmapView<'_>)

Syntatic sugar for .or_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

bitmap1 |= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(bitmap1.contains(25));
§

impl BitOrAssign<BitmapView<'_>> for Bitmap

§

fn bitor_assign(&mut self, other: BitmapView<'_>)

Syntatic sugar for .or_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

bitmap1 |= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(bitmap1.contains(25));
§

impl BitOrAssign for Bitmap

§

fn bitor_assign(&mut self, other: Bitmap)

Syntatic sugar for .or_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15]);
let bitmap2 = Bitmap::of(&[25]);

bitmap1 |= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(bitmap1.contains(25));
§

impl BitXor<&Bitmap> for &Bitmap

§

fn bitxor(self, other: &Bitmap) -> Bitmap

Syntatic sugar for .xor

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 ^ bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the ^ operator.
§

impl BitXor<&Bitmap> for Bitmap

§

fn bitxor(self, other: &Bitmap) -> Bitmap

Syntatic sugar for .xor

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 ^ bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the ^ operator.
§

impl BitXor<Bitmap> for &Bitmap

§

fn bitxor(self, other: Bitmap) -> Bitmap

Syntatic sugar for .xor

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 ^ bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the ^ operator.
§

impl BitXor for Bitmap

§

fn bitxor(self, other: Bitmap) -> Bitmap

Syntatic sugar for .xor

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 ^ bitmap2;

assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the ^ operator.
§

impl BitXorAssign<&Bitmap> for Bitmap

§

fn bitxor_assign(&mut self, other: &Bitmap)

Syntatic sugar for .xor_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 ^= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(bitmap1.contains(35));
§

impl BitXorAssign<&BitmapView<'_>> for Bitmap

§

fn bitxor_assign(&mut self, other: &BitmapView<'_>)

Syntatic sugar for .xor_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 ^= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(bitmap1.contains(35));
§

impl BitXorAssign<BitmapView<'_>> for Bitmap

§

fn bitxor_assign(&mut self, other: BitmapView<'_>)

Syntatic sugar for .xor_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 ^= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(bitmap1.contains(35));
§

impl BitXorAssign for Bitmap

§

fn bitxor_assign(&mut self, other: Bitmap)

Syntatic sugar for .xor_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 ^= bitmap2;

assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(bitmap1.contains(35));
§

impl Clone for Bitmap

§

fn clone(&self) -> Bitmap

Create a copy of a Bitmap

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::new();
bitmap1.add(11);

let bitmap2 = bitmap1.clone();

assert_eq!(bitmap1, bitmap2);
§

fn clone_from(&mut self, source: &Bitmap)

Performs copy-assignment from source. Read more
§

impl Debug for Bitmap

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Bitmap

§

fn default() -> Bitmap

Returns the “default value” for a type. Read more
§

impl Drop for Bitmap

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl Extend<u32> for Bitmap

§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = u32>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
§

impl From<&[u32]> for Bitmap

Create a new bitmap from a slice of u32 values

§Examples

use croaring::Bitmap;

let data: &[u32] = &[1, 2, 3];

let bitmap1 = Bitmap::from(data);
let bitmap2 = Bitmap::from_range(1..=3);
assert_eq!(bitmap1, bitmap2);
§

fn from(values: &[u32]) -> Bitmap

Converts to this type from the input type.
§

impl<const N: usize> From<[u32; N]> for Bitmap

Create a new bitmap from an array of u32 values

§Examples

use croaring::Bitmap;

let bitmap1 = Bitmap::from([1, 2, 3]);
let bitmap2 = Bitmap::from_range(1..=3);
assert_eq!(bitmap1, bitmap2);
§

fn from(values: [u32; N]) -> Bitmap

Converts to this type from the input type.
§

impl FromIterator<u32> for Bitmap

§

fn from_iter<I>(iter: I) -> Bitmap
where I: IntoIterator<Item = u32>,

Convenience method for creating bitmap from iterator.

§Examples
use croaring::Bitmap;

let bitmap: Bitmap = (1..3).collect();

assert!(!bitmap.is_empty());
assert!(bitmap.contains(1));
assert!(bitmap.contains(2));
assert_eq!(bitmap.cardinality(), 2);
§

impl PartialEq<BitmapView<'_>> for Bitmap

§

fn eq(&self, other: &BitmapView<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq for Bitmap

§

fn eq(&self, other: &Bitmap) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Sub<&Bitmap> for &Bitmap

§

fn sub(self, other: &Bitmap) -> Bitmap

Syntatic sugar for .andnot

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 - bitmap2;

assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the - operator.
§

impl Sub<&Bitmap> for Bitmap

§

fn sub(self, other: &Bitmap) -> Bitmap

Syntatic sugar for .andnot

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 - bitmap2;

assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the - operator.
§

impl Sub<Bitmap> for &Bitmap

§

fn sub(self, other: Bitmap) -> Bitmap

Syntatic sugar for .andnot

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 - bitmap2;

assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the - operator.
§

impl Sub for Bitmap

§

fn sub(self, other: Bitmap) -> Bitmap

Syntatic sugar for .andnot

§Examples
use croaring::Bitmap;

let bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

let bitmap3 = bitmap1 - bitmap2;

assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
§

type Output = Bitmap

The resulting type after applying the - operator.
§

impl SubAssign<&Bitmap> for Bitmap

§

fn sub_assign(&mut self, other: &Bitmap)

Syntatic sugar for .andnot_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 -= bitmap2;

assert_eq!(bitmap1.cardinality(), 1);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(!bitmap1.contains(35));
§

impl SubAssign<&BitmapView<'_>> for Bitmap

§

fn sub_assign(&mut self, other: &BitmapView<'_>)

Syntatic sugar for .andnot_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 -= bitmap2;

assert_eq!(bitmap1.cardinality(), 1);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(!bitmap1.contains(35));
§

impl SubAssign<BitmapView<'_>> for Bitmap

§

fn sub_assign(&mut self, other: BitmapView<'_>)

Syntatic sugar for .andnot_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 -= bitmap2;

assert_eq!(bitmap1.cardinality(), 1);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(!bitmap1.contains(35));
§

impl SubAssign for Bitmap

§

fn sub_assign(&mut self, other: Bitmap)

Syntatic sugar for .andnot_inplace

§Examples
use croaring::Bitmap;

let mut bitmap1 = Bitmap::of(&[15, 25]);
let bitmap2 = Bitmap::of(&[25, 35]);

bitmap1 -= bitmap2;

assert_eq!(bitmap1.cardinality(), 1);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(!bitmap1.contains(35));
§

impl Eq for Bitmap

§

impl Send for Bitmap

§

impl Sync for Bitmap

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

§

impl<T> Ungil for T
where T: Send,