Struct croaring::Bitmap [] [src]

pub struct Bitmap {
    // some fields omitted
}

Methods

impl Bitmap
[src]

fn create() -> Self

Creates a new bitmap (initially empty)

Examples

use croaring::Bitmap;

let bitmap = Bitmap::create();

assert!(bitmap.is_empty());

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());

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());

fn remove(&mut self, element: u32)

Remove 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());

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));

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);

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));

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));

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));

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));

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));

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));

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));

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));

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));

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));

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));

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));

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));

fn as_slice(&self) -> &[u32]

Creates a new slice 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.as_slice(), [15, 25]);
assert!(bitmap.as_slice() != [10, 15, 25])

fn get_serialized_size_in_bytes(&self) -> usize

Computes the serialized size in bytes of the Bitmap.

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);

fn deserialize(buffer: &[u8]) -> Self

Given a serialized bitmap as slice of bytes returns a bitmap instance. See example of #serialize function.

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);

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());

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());

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());

Trait Implementations

impl Debug for Bitmap
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl PartialEq for Bitmap
[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl Clone for Bitmap
[src]

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);

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl Drop for Bitmap
[src]

fn drop(&mut self)

A method called when the value goes out of scope. Read more

impl FromIterator<u32> for Bitmap
[src]

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);

impl<'a> IntoIterator for &'a Bitmap
[src]

type Item = &'a u32

The type of the elements being iterated over.

type IntoIter = Iter<'a, u32>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter

Convenience method for creating iterators of the bitmap elements.

Examples

use croaring::Bitmap;

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

for (_, element) in bitmap.into_iter().enumerate() {
   assert!(bitmap.contains(*element));
}

impl BitAnd for Bitmap
[src]

type Output = Bitmap

The resulting type after applying the & operator

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));

impl BitAndAssign for Bitmap
[src]

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));

impl BitOr for Bitmap
[src]

type Output = Bitmap

The resulting type after applying the | operator

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));

impl BitOrAssign for Bitmap
[src]

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));

impl BitXor for Bitmap
[src]

type Output = Bitmap

The resulting type after applying the ^ operator

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));

impl BitXorAssign for Bitmap
[src]

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));