pub struct Bitmap { /* private fields */ }
Implementations
sourceimpl Bitmap
impl Bitmap
sourcepub fn create() -> Self
pub fn create() -> Self
Creates a new bitmap (initially empty)
Examples
use croaring::Bitmap;
let bitmap = Bitmap::create();
assert!(bitmap.is_empty());
sourcepub fn create_with_capacity(capacity: u32) -> Self
pub fn create_with_capacity(capacity: u32) -> Self
Creates a new bitmap (initially empty) with a provided container-storage capacity (it is a performance hint).
Examples
use croaring::Bitmap;
let bitmap = Bitmap::create_with_capacity(100_000);
assert!(bitmap.is_empty());
sourcepub fn add_many(&mut self, elements: &[u32])
pub fn add_many(&mut self, elements: &[u32])
Add the integer element to the bitmap
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add_many(&[1, 2, 3]);
assert!(!bitmap.is_empty());
assert!(bitmap.contains(1));
assert!(bitmap.contains(2));
assert!(bitmap.contains(3));
sourcepub fn add(&mut self, element: u32)
pub fn add(&mut self, element: u32)
Add the integer element to the bitmap
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add(1);
assert!(!bitmap.is_empty());
sourcepub fn add_checked(&mut self, element: u32) -> bool
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::create();
assert!(bitmap.add_checked(1));
assert!(!bitmap.add_checked(1));
sourcepub fn add_range(&mut self, range: Range<u64>)
pub fn add_range(&mut self, range: Range<u64>)
Add all values in range [range_min, range_max)
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
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::create();
bitmap2.add_range((3..1));
assert!(bitmap2.is_empty());
let mut bitmap3 = Bitmap::create();
bitmap3.add_range((3..3));
assert!(bitmap3.is_empty());
sourcepub fn remove_range(&mut self, range: Range<u64>)
pub fn remove_range(&mut self, range: Range<u64>)
Remove all values in range [range_min, range_max)
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
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));
sourcepub fn add_range_closed(&mut self, range: Range<u32>)
pub fn add_range_closed(&mut self, range: Range<u32>)
Add all values in range [range_min, range_max]
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add_range_closed((1..3));
assert!(!bitmap1.is_empty());
assert!(bitmap1.contains(1));
assert!(bitmap1.contains(2));
assert!(bitmap1.contains(3));
let mut bitmap2 = Bitmap::create();
bitmap2.add_range_closed((3..1));
assert!(bitmap2.is_empty());
let mut bitmap3 = Bitmap::create();
bitmap3.add_range_closed((3..3));
assert!(!bitmap3.is_empty());
assert!(bitmap3.contains(3));
sourcepub fn remove_range_closed(&mut self, range: Range<u32>)
pub fn remove_range_closed(&mut self, range: Range<u32>)
Remove all values in range [range_min, range_max]
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add_range((1..4));
assert!(!bitmap.is_empty());
bitmap.remove_range_closed((1..3));
assert!(!bitmap.contains(1));
assert!(!bitmap.contains(2));
assert!(!bitmap.contains(3));
sourcepub fn contains_range(&mut self, range: Range<u64>) -> bool
pub fn contains_range(&mut self, range: Range<u64>) -> bool
Check whether a range of values of range are present
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add_range((1..3));
assert!(bitmap.contains_range((1..3)));
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Empties the bitmap
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add(1);
bitmap.add(2);
bitmap.clear();
assert!(bitmap.is_empty());
sourcepub fn remove(&mut self, element: u32)
pub fn remove(&mut self, element: u32)
Clear the integer element from the bitmap
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add(1);
bitmap.remove(1);
assert!(bitmap.is_empty());
sourcepub fn remove_checked(&mut self, element: u32) -> bool
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::create();
bitmap.add(1);
assert!(bitmap.remove_checked(1));
assert!(!bitmap.remove_checked(1));
sourcepub fn contains(&self, element: u32) -> bool
pub fn contains(&self, element: u32) -> bool
Contains returns true if the integer element is contained in the bitmap
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add(1);
assert!(bitmap.contains(1));
assert!(!bitmap.contains(2));
sourcepub fn range_cardinality(&self, range: Range<u64>) -> u64
pub fn range_cardinality(&self, range: Range<u64>) -> u64
Returns number of elements in range [range_start, range_end).
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add(1);
bitmap.add(3);
bitmap.add(4);
assert_eq!(bitmap.range_cardinality((0..1)), 0);
assert_eq!(bitmap.range_cardinality((0..2)), 1);
assert_eq!(bitmap.range_cardinality((2..5)), 2);
assert_eq!(bitmap.range_cardinality((0..5)), 3);
sourcepub fn cardinality(&self) -> u64
pub fn cardinality(&self) -> u64
Returns the number of integers contained in the bitmap
Examples
use croaring::Bitmap;
let mut bitmap = Bitmap::create();
bitmap.add(1);
assert_eq!(bitmap.cardinality(), 1);
bitmap.add(2);
assert_eq!(bitmap.cardinality(), 2);
sourcepub fn and(&self, other: &Self) -> Self
pub fn and(&self, other: &Self) -> Self
And computes the intersection between two bitmaps and returns the result as a new bitmap
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(1);
let mut bitmap2 = Bitmap::create();
bitmap2.add(1);
bitmap2.add(2);
let bitmap3 = bitmap1.and(&bitmap2);
assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
sourcepub fn and_inplace(&mut self, other: &Self)
pub fn and_inplace(&mut self, other: &Self)
Computes the intersection between two bitmaps and stores the result in the current bitmap
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let mut bitmap3 = Bitmap::create();
bitmap3.add(15);
let mut bitmap4 = Bitmap::create();
bitmap4.add(15);
bitmap4.add(25);
bitmap1.and_inplace(&bitmap2);
assert!(bitmap1.cardinality() == 0);
assert!(!bitmap1.contains(15));
assert!(!bitmap1.contains(25));
bitmap3.and_inplace(&bitmap4);
assert!(bitmap3.cardinality() == 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
sourcepub fn or(&self, other: &Self) -> Self
pub fn or(&self, other: &Self) -> Self
Or computes the union between two bitmaps and returns the result as a new bitmap
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let bitmap3 = bitmap1.or(&bitmap2);
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
sourcepub fn or_inplace(&mut self, other: &Self)
pub fn or_inplace(&mut self, other: &Self)
Computes the union between two bitmaps and stores the result in the current bitmap.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap1.or_inplace(&bitmap2);
assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(bitmap1.contains(25));
sourcepub fn fast_or(bitmaps: &[&Bitmap]) -> Self
pub fn fast_or(bitmaps: &[&Bitmap]) -> Self
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 mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let mut bitmap3 = Bitmap::create();
bitmap3.add(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));
sourcepub fn fast_or_heap(bitmaps: &[&Bitmap]) -> Self
pub fn fast_or_heap(bitmaps: &[&Bitmap]) -> Self
Compute the union of ‘number’ bitmaps using a heap. This can sometimes be faster than Bitmap::fast_or.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let mut bitmap3 = Bitmap::create();
bitmap3.add(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));
sourcepub fn xor(&self, other: &Self) -> Self
pub fn xor(&self, other: &Self) -> Self
Computes the symmetric difference (xor) between two bitmaps and returns new bitmap.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = bitmap1.xor(&bitmap2);
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
sourcepub fn xor_inplace(&mut self, other: &Self)
pub fn xor_inplace(&mut self, other: &Self)
Inplace version of roaring_bitmap_xor, stores result in current bitmap.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
bitmap1.xor_inplace(&bitmap2);
assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(bitmap1.contains(35));
sourcepub fn fast_xor(bitmaps: &[&Bitmap]) -> Self
pub fn fast_xor(bitmaps: &[&Bitmap]) -> Self
Computes the symmetric difference (xor) between multiple bitmaps and returns new bitmap as a result.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = Bitmap::fast_xor(&[&bitmap1, &bitmap2]);
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
sourcepub fn andnot(&self, other: &Self) -> Self
pub fn andnot(&self, other: &Self) -> Self
Computes the difference between two bitmaps and returns the result.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = bitmap1.andnot(&bitmap2);
assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
sourcepub fn andnot_inplace(&mut self, other: &Self)
pub fn andnot_inplace(&mut self, other: &Self)
Computes the difference between two bitmaps and stores the result in the current bitmap.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(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::create();
bitmap3.add(15);
let mut bitmap4 = Bitmap::create();
bitmap3.andnot_inplace(&bitmap4);
assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
sourcepub fn flip(&self, range: Range<u64>) -> Self
pub fn flip(&self, range: Range<u64>) -> Self
Negates the bits in the given range (i.e., [rangeStart..rangeEnd)), any integer present in this range and in the bitmap is removed. Returns result as a new bitmap.
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(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));
sourcepub fn flip_inplace(&mut self, range: Range<u64>)
pub fn flip_inplace(&mut self, range: Range<u64>)
Negates the bits in the given range (i.e., [rangeStart..rangeEnd)), 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::create();
bitmap1.add(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));
sourcepub fn to_vec(&self) -> Vec<u32>
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 mut bitmap = Bitmap::create();
bitmap.add(15);
bitmap.add(25);
assert_eq!(bitmap.to_vec(), [15, 25]);
assert!(bitmap.to_vec() != [10, 15, 25]);
sourcepub fn get_serialized_size_in_bytes(&self) -> usize
pub fn get_serialized_size_in_bytes(&self) -> usize
Computes the serialized size in bytes of the Bitmap.
sourcepub fn serialize(&self) -> Vec<u8>
pub fn serialize(&self) -> Vec<u8>
Serializes a bitmap to a slice of bytes.
Examples
use croaring::Bitmap;
let original_bitmap: Bitmap = (1..5).collect();
let serialized_buffer = original_bitmap.serialize();
let deserialized_bitmap = Bitmap::deserialize(&serialized_buffer);
assert_eq!(original_bitmap, deserialized_bitmap);
sourcepub fn try_deserialize(buffer: &[u8]) -> Option<Self>
pub fn try_deserialize(buffer: &[u8]) -> Option<Self>
Given a serialized bitmap as slice of bytes returns a bitmap instance. See example of #serialize function.
On invalid input returns None.
Examples
use croaring::Bitmap;
let original_bitmap: Bitmap = (1..5).collect();
let serialized_buffer = original_bitmap.serialize();
let deserialized_bitmap = Bitmap::try_deserialize(&serialized_buffer);
assert_eq!(original_bitmap, deserialized_bitmap.unwrap());
let invalid_buffer: Vec<u8> = vec![3];
let deserialized_bitmap = Bitmap::try_deserialize(&invalid_buffer);
assert!(deserialized_bitmap.is_none());
sourcepub fn deserialize(buffer: &[u8]) -> Self
pub fn deserialize(buffer: &[u8]) -> Self
Given a serialized bitmap as slice of bytes returns a bitmap instance. See example of #serialize function.
On invalid input returns empty bitmap.
sourcepub fn of(elements: &[u32]) -> Self
pub fn of(elements: &[u32]) -> Self
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::create();
for element in &elements {
bitmap2.add(*element);
}
assert!(bitmap.contains(1));
assert!(bitmap.contains(2));
assert!(!bitmap.contains(3));
assert_eq!(bitmap, bitmap2);
sourcepub fn run_optimize(&mut self) -> bool
pub fn run_optimize(&mut self) -> bool
Compresses of the bitmap. Returns true if the bitmap was modified.
Examples
use croaring::Bitmap;
let mut bitmap: Bitmap = (100..1000).collect();
assert_eq!(bitmap.cardinality(), 900);
assert!(bitmap.run_optimize());
sourcepub fn remove_run_compression(&mut self) -> bool
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());
sourcepub fn is_empty(&self) -> bool
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::create();
assert!(bitmap.is_empty());
bitmap.add(1);
assert!(!bitmap.is_empty());
sourcepub fn is_subset(&self, other: &Self) -> bool
pub fn is_subset(&self, other: &Self) -> 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));
sourcepub fn is_strict_subset(&self, other: &Self) -> bool
pub fn is_strict_subset(&self, other: &Self) -> 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));
sourcepub fn intersect(&self, other: &Self) -> bool
pub fn intersect(&self, other: &Self) -> 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);
sourcepub fn jaccard_index(&self, other: &Self) -> f64
pub fn jaccard_index(&self, other: &Self) -> 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);
sourcepub fn and_cardinality(&self, other: &Self) -> u64
pub fn and_cardinality(&self, other: &Self) -> u64
Return the size of the intersection between Self and &other
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(1);
let mut bitmap2 = Bitmap::create();
bitmap2.add(1);
bitmap2.add(2);
assert_eq!(bitmap1.and_cardinality(&bitmap2), 1);
sourcepub fn or_cardinality(&self, other: &Self) -> u64
pub fn or_cardinality(&self, other: &Self) -> u64
Return the size of the union between Self and &other
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
assert_eq!(bitmap1.or_cardinality(&bitmap2), 2);
sourcepub fn andnot_cardinality(&self, other: &Self) -> u64
pub fn andnot_cardinality(&self, other: &Self) -> u64
Return the size of the difference between Self and &other
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
assert_eq!(bitmap1.andnot_cardinality(&bitmap2), 1);
sourcepub fn xor_cardinality(&self, other: &Self) -> u64
pub fn xor_cardinality(&self, other: &Self) -> u64
Return the size of the symmetric difference between Self and &other
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
assert_eq!(bitmap1.xor_cardinality(&bitmap2), 2);
sourcepub fn minimum(&self) -> Option<u32>
pub fn minimum(&self) -> Option<u32>
Returns the smallest value in the set. Returns std::u32::MAX if the set is empty.
Examples
use croaring::Bitmap;
let mut bitmap: Bitmap = (5..10).collect();
let empty_bitmap: Bitmap = Bitmap::create();
assert_eq!(bitmap.minimum(), Some(5));
assert_eq!(empty_bitmap.minimum(), None);
bitmap.add(3);
assert_eq!(bitmap.minimum(), Some(3));
sourcepub fn maximum(&self) -> Option<u32>
pub fn maximum(&self) -> Option<u32>
Returns the greatest value in the set. Returns 0 if the set is empty.
Examples
use croaring::Bitmap;
let mut bitmap: Bitmap = (5..10).collect();
let empty_bitmap: Bitmap = Bitmap::create();
assert_eq!(bitmap.maximum(), Some(9));
assert_eq!(empty_bitmap.maximum(), None);
bitmap.add(15);
assert_eq!(bitmap.maximum(), Some(15));
sourcepub fn rank(&self, x: u32) -> u64
pub fn rank(&self, x: u32) -> u64
Rank returns the number of values smaller or equal to x.
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);
sourcepub fn select(&self, rank: u32) -> Option<u32>
pub fn select(&self, rank: u32) -> Option<u32>
Select returns the element having the designated rank, if it exists If the size of the roaring bitmap is strictly greater than rank, then this function returns element of given rank wrapped in Some. Otherwise, it returns None.
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);
sourcepub fn statistics(&self) -> Statistics
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.sum_value, 4950);
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.sum_value, 4950);
assert_eq!(statistics.cardinality, 99);
sourceimpl Bitmap
impl Bitmap
sourcepub fn iter(&self) -> BitmapIterator<'_>ⓘNotable traits for BitmapIterator<'a>impl<'a> Iterator for BitmapIterator<'a> type Item = u32;
pub fn iter(&self) -> BitmapIterator<'_>ⓘNotable traits for BitmapIterator<'a>impl<'a> Iterator for BitmapIterator<'a> type Item = u32;
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::create();
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);
Trait Implementations
sourceimpl<'a> BitAnd<&'a Bitmap> for Bitmap
impl<'a> BitAnd<&'a Bitmap> for Bitmap
sourcefn bitand(self, other: &'a Bitmap) -> Bitmap
fn bitand(self, other: &'a Bitmap) -> Bitmap
Syntactic sugar for .and
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(1);
let mut bitmap2 = Bitmap::create();
bitmap2.add(1);
bitmap2.add(2);
let bitmap3 = bitmap1 & &bitmap2;
assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
sourceimpl<'a, 'b> BitAnd<&'a Bitmap> for &'b Bitmap
impl<'a, 'b> BitAnd<&'a Bitmap> for &'b Bitmap
sourcefn bitand(self, other: &'a Bitmap) -> Bitmap
fn bitand(self, other: &'a Bitmap) -> Bitmap
Syntactic sugar for .and
Examples
use croaring::Bitmap;
let mut bitmap1: Bitmap = Bitmap::create();
bitmap1.add(1);
let mut bitmap2 = Bitmap::create();
bitmap2.add(1);
bitmap2.add(2);
let bitmap3 = &bitmap1 & &bitmap2;
assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
sourceimpl BitAnd<Bitmap> for Bitmap
impl BitAnd<Bitmap> for Bitmap
sourcefn bitand(self, other: Bitmap) -> Bitmap
fn bitand(self, other: Bitmap) -> Bitmap
Syntactic sugar for .and
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(1);
let mut bitmap2 = Bitmap::create();
bitmap2.add(1);
bitmap2.add(2);
let bitmap3 = bitmap1 & bitmap2;
assert!(bitmap3.contains(1));
assert!(!bitmap3.contains(2));
sourceimpl BitAndAssign<Bitmap> for Bitmap
impl BitAndAssign<Bitmap> for Bitmap
sourcefn bitand_assign(&mut self, other: Bitmap)
fn bitand_assign(&mut self, other: Bitmap)
Syntactic sugar for .and_inplace
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let mut bitmap3 = Bitmap::create();
bitmap3.add(15);
let mut bitmap4 = Bitmap::create();
bitmap4.add(15);
bitmap4.add(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));
sourceimpl<'a> BitOr<&'a Bitmap> for Bitmap
impl<'a> BitOr<&'a Bitmap> for Bitmap
sourcefn bitor(self, other: &'a Bitmap) -> Bitmap
fn bitor(self, other: &'a Bitmap) -> Bitmap
Syntatic sugar for .or
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let bitmap3 = bitmap1 | &bitmap2;
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
sourceimpl<'a, 'b> BitOr<&'a Bitmap> for &'b Bitmap
impl<'a, 'b> BitOr<&'a Bitmap> for &'b Bitmap
sourcefn bitor(self, other: &'a Bitmap) -> Bitmap
fn bitor(self, other: &'a Bitmap) -> Bitmap
Syntatic sugar for .or
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let bitmap3 = &bitmap1 | &bitmap2;
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
sourceimpl BitOr<Bitmap> for Bitmap
impl BitOr<Bitmap> for Bitmap
sourcefn bitor(self, other: Bitmap) -> Bitmap
fn bitor(self, other: Bitmap) -> Bitmap
Syntatic sugar for .or
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
let bitmap3 = bitmap1 | bitmap2;
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(bitmap3.contains(25));
sourceimpl BitOrAssign<Bitmap> for Bitmap
impl BitOrAssign<Bitmap> for Bitmap
sourcefn bitor_assign(&mut self, other: Bitmap)
fn bitor_assign(&mut self, other: Bitmap)
Syntatic sugar for .or_inplace
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap1 |= bitmap2;
assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(bitmap1.contains(25));
sourceimpl<'a> BitXor<&'a Bitmap> for Bitmap
impl<'a> BitXor<&'a Bitmap> for Bitmap
sourcefn bitxor(self, other: &'a Bitmap) -> Bitmap
fn bitxor(self, other: &'a Bitmap) -> Bitmap
Syntatic sugar for .xor
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = bitmap1 ^ &bitmap2;
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
sourceimpl<'a, 'b> BitXor<&'a Bitmap> for &'b Bitmap
impl<'a, 'b> BitXor<&'a Bitmap> for &'b Bitmap
sourcefn bitxor(self, other: &'a Bitmap) -> Bitmap
fn bitxor(self, other: &'a Bitmap) -> Bitmap
Syntatic sugar for .xor
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = &bitmap1 ^ &bitmap2;
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
sourceimpl BitXor<Bitmap> for Bitmap
impl BitXor<Bitmap> for Bitmap
sourcefn bitxor(self, other: Bitmap) -> Bitmap
fn bitxor(self, other: Bitmap) -> Bitmap
Syntatic sugar for .xor
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = bitmap1 ^ bitmap2;
assert!(bitmap3.cardinality() == 2);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(bitmap3.contains(35));
sourceimpl BitXorAssign<Bitmap> for Bitmap
impl BitXorAssign<Bitmap> for Bitmap
sourcefn bitxor_assign(&mut self, other: Bitmap)
fn bitxor_assign(&mut self, other: Bitmap)
Syntatic sugar for .xor_inplace
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
bitmap1 ^= bitmap2;
assert!(bitmap1.cardinality() == 2);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(bitmap1.contains(35));
sourceimpl Clone for Bitmap
impl Clone for Bitmap
sourcefn clone(&self) -> Bitmap
fn clone(&self) -> Bitmap
Create a copy of a Bitmap
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(11);
let bitmap2 = bitmap1.clone();
assert_eq!(bitmap1, bitmap2);
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Extend<u32> for Bitmap
impl Extend<u32> for Bitmap
sourcefn extend<T: IntoIterator<Item = u32>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = u32>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl FromIterator<u32> for Bitmap
impl FromIterator<u32> for Bitmap
sourcefn from_iter<I: IntoIterator<Item = u32>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = u32>>(iter: I) -> Self
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);
sourceimpl<'a> Sub<&'a Bitmap> for Bitmap
impl<'a> Sub<&'a Bitmap> for Bitmap
sourcefn sub(self, other: &'a Bitmap) -> Bitmap
fn sub(self, other: &'a Bitmap) -> Bitmap
Syntatic sugar for .andnot
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = bitmap1 - &bitmap2;
assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
sourceimpl<'a, 'b> Sub<&'a Bitmap> for &'b Bitmap
impl<'a, 'b> Sub<&'a Bitmap> for &'b Bitmap
sourcefn sub(self, other: &'a Bitmap) -> Bitmap
fn sub(self, other: &'a Bitmap) -> Bitmap
Syntatic sugar for .andnot
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = &bitmap1 - &bitmap2;
assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
sourceimpl Sub<Bitmap> for Bitmap
impl Sub<Bitmap> for Bitmap
sourcefn sub(self, other: Bitmap) -> Bitmap
fn sub(self, other: Bitmap) -> Bitmap
Syntatic sugar for .andnot
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
let bitmap3 = bitmap1 - bitmap2;
assert_eq!(bitmap3.cardinality(), 1);
assert!(bitmap3.contains(15));
assert!(!bitmap3.contains(25));
assert!(!bitmap3.contains(35));
sourceimpl SubAssign<Bitmap> for Bitmap
impl SubAssign<Bitmap> for Bitmap
sourcefn sub_assign(&mut self, other: Bitmap)
fn sub_assign(&mut self, other: Bitmap)
Syntatic sugar for .andnot_inplace
Examples
use croaring::Bitmap;
let mut bitmap1 = Bitmap::create();
bitmap1.add(15);
bitmap1.add(25);
let mut bitmap2 = Bitmap::create();
bitmap2.add(25);
bitmap2.add(35);
bitmap1.andnot_inplace(&bitmap2);
assert_eq!(bitmap1.cardinality(), 1);
assert!(bitmap1.contains(15));
assert!(!bitmap1.contains(25));
assert!(!bitmap1.contains(35));
impl Send for Bitmap
impl Sync for Bitmap
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more