Struct roaring::RoaringBitmap [-] [+] [src]

pub struct RoaringBitmap<Size: ExtInt + Halveable> where <Size as Halveable>::HalfSize: ExtInt {
    // some fields omitted
}

A compressed bitmap using the Roaring bitmap compression scheme.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();

// insert all primes less than 10
rb.insert(2);
rb.insert(3);
rb.insert(5);
rb.insert(7);
println!("total bits set to true: {}", rb.len());

Methods

impl<Size: ExtInt + Halveable> RoaringBitmap<Size>

fn new() -> RoaringBitmap<Size>

Creates an empty RoaringBitmap.

Examples

use roaring::RoaringBitmap;
let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();

fn insert(&mut self, value: Size) -> bool

Adds a value to the set. Returns true if the value was not already present in the set.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();
assert_eq!(rb.insert(3), true);
assert_eq!(rb.insert(3), false);
assert_eq!(rb.contains(3), true);

fn remove(&mut self, value: Size) -> bool

Removes a value from the set. Returns true if the value was present in the set.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();
rb.insert(3);
assert_eq!(rb.remove(3), true);
assert_eq!(rb.remove(3), false);
assert_eq!(rb.contains(3), false);

fn contains(&self, value: Size) -> bool

Returns true if this set contains the specified integer.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();
rb.insert(1);
assert_eq!(rb.contains(0), false);
assert_eq!(rb.contains(1), true);
assert_eq!(rb.contains(100), false);

fn clear(&mut self)

Clears all integers in this set.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();
rb.insert(1);
assert_eq!(rb.contains(1), true);
rb.clear();
assert_eq!(rb.contains(1), false);

fn is_empty(&self) -> bool

Returns true if there are no integers in this set.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();
assert_eq!(rb.is_empty(), true);

rb.insert(3);
assert_eq!(rb.is_empty(), false);

fn len(&self) -> Size

Returns the number of distinct integers added to the set.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();
assert_eq!(rb.len(), 0);

rb.insert(3);
assert_eq!(rb.len(), 1);

rb.insert(3);
rb.insert(4);
assert_eq!(rb.len(), 2);

fn iter<'a>(&'a self) -> Iter<'a, Size> where <Size as Halveable>::HalfSize: 'a

Iterator over each value stored in the RoaringBitmap, guarantees values are ordered by value.

Examples

use roaring::RoaringBitmap;

let mut rb: RoaringBitmap<u32> = RoaringBitmap::new();

rb.insert(1);
rb.insert(6);
rb.insert(4);

let mut iter = rb.iter();

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(4));
assert_eq!(iter.next(), Some(6));
assert_eq!(iter.next(), None);

fn is_disjoint(&self, other: &RoaringBitmap<Size>) -> bool

Returns true if the set has no elements in common with other. This is equivalent to checking for an empty intersection.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = RoaringBitmap::new();
let mut rb2: RoaringBitmap<u32> = RoaringBitmap::new();

rb1.insert(1);

assert_eq!(rb1.is_disjoint(&rb2), true);

rb2.insert(1);

assert_eq!(rb1.is_disjoint(&rb2), false);

fn is_subset(&self, other: &RoaringBitmap<Size>) -> bool

Returns true if this set is a subset of other.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = RoaringBitmap::new();
let mut rb2: RoaringBitmap<u32> = RoaringBitmap::new();

rb1.insert(1);

assert_eq!(rb1.is_subset(&rb2), false);

rb2.insert(1);

assert_eq!(rb1.is_subset(&rb2), true);

rb1.insert(2);

assert_eq!(rb1.is_subset(&rb2), false);

fn is_superset(&self, other: &RoaringBitmap<Size>) -> bool

Returns true if this set is a superset of other.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = RoaringBitmap::new();
let mut rb2: RoaringBitmap<u32> = RoaringBitmap::new();

rb1.insert(1);

assert_eq!(rb2.is_superset(&rb1), false);

rb2.insert(1);

assert_eq!(rb2.is_superset(&rb1), true);

rb1.insert(2);

assert_eq!(rb2.is_superset(&rb1), false);

fn union<'a>(&'a self, other: &'a RoaringBitmap<Size>) -> UnionIter<'a, Size> where <Size as Halveable>::HalfSize: 'a

Returns an iterator over the union of this bitmap with the other bitmap.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = RoaringBitmap::new();
let mut rb2: RoaringBitmap<u32> = RoaringBitmap::new();

rb1.insert(1);
rb1.insert(2);

rb2.insert(1);
rb2.insert(3);

let mut iter = rb1.union(&rb2);

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), None);

fn intersection<'a>(&'a self, other: &'a RoaringBitmap<Size>) -> IntersectionIter<'a, Size> where <Size as Halveable>::HalfSize: 'a

Returns an iterator over the intersection of this bitmap with the other bitmap.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = RoaringBitmap::new();
let mut rb2: RoaringBitmap<u32> = RoaringBitmap::new();

rb1.insert(1);
rb1.insert(2);
rb1.insert(4);

rb2.insert(1);
rb2.insert(3);
rb2.insert(4);

let mut iter = rb1.intersection(&rb2);

assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(4));
assert_eq!(iter.next(), None);

fn difference<'a>(&'a self, other: &'a RoaringBitmap<Size>) -> DifferenceIter<'a, Size> where <Size as Halveable>::HalfSize: 'a

Returns an iterator over the set of values in this that are not in other.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = RoaringBitmap::new();
let mut rb2: RoaringBitmap<u32> = RoaringBitmap::new();

rb1.insert(1);
rb1.insert(2);
rb1.insert(4);

rb2.insert(1);
rb2.insert(3);
rb2.insert(4);

let mut iter1 = rb1.difference(&rb2);

assert_eq!(iter1.next(), Some(2));
assert_eq!(iter1.next(), None);

let mut iter2 = rb2.difference(&rb1);

assert_eq!(iter2.next(), Some(3));
assert_eq!(iter2.next(), None);

fn symmetric_difference<'a>(&'a self, other: &'a RoaringBitmap<Size>) -> SymmetricDifferenceIter<'a, Size> where <Size as Halveable>::HalfSize: 'a

Returns an iterator over the set of values in this that are not in other + in other that are not in this.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = RoaringBitmap::new();
let mut rb2: RoaringBitmap<u32> = RoaringBitmap::new();

rb1.insert(1);
rb1.insert(2);
rb1.insert(4);

rb2.insert(1);
rb2.insert(3);
rb2.insert(4);

let mut iter = rb1.symmetric_difference(&rb2);

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

fn union_with(&mut self, other: &RoaringBitmap<Size>)

Unions in-place with the specified other bitmap.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..5u32).collect();
let rb3: RoaringBitmap<u32> = (1..5u32).collect();

rb1.union_with(&rb2);

assert_eq!(rb1, rb3);

fn intersect_with(&mut self, other: &RoaringBitmap<Size>)

Intersects in-place with the specified other bitmap.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..5u32).collect();
let rb3: RoaringBitmap<u32> = (3..4u32).collect();

rb1.intersect_with(&rb2);

assert_eq!(rb1, rb3);

fn difference_with(&mut self, other: &RoaringBitmap<Size>)

Removes all values in the specified other bitmap from self, in-place.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..5u32).collect();
let rb3: RoaringBitmap<u32> = (1..3u32).collect();

rb1.difference_with(&rb2);

assert_eq!(rb1, rb3);

fn symmetric_difference_with(&mut self, other: &RoaringBitmap<Size>)

Replaces this bitmap with one that is equivalent to self XOR other.

Examples

use roaring::RoaringBitmap;

let mut rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..6u32).collect();
let rb3: RoaringBitmap<u32> = ((1..3u32).chain(4..6u32)).collect();

rb1.symmetric_difference_with(&rb2);

assert_eq!(rb1, rb3);

Trait Implementations

impl<Size: ExtInt + Halveable> IntoIterator for RoaringBitmap<Size>

type Item = Size

type IntoIter = <Vec<Size> as IntoIterator>::IntoIter

fn into_iter(self) -> <RoaringBitmap<Size> as IntoIterator>::IntoIter

impl<Size: ExtInt + Halveable> FromIterator<Size> for RoaringBitmap<Size>

fn from_iter<I: IntoIterator<Item=Size>>(iterator: I) -> RoaringBitmap<Size>

impl<'a, Size: ExtInt + Halveable + 'a> FromIterator<&'a Size> for RoaringBitmap<Size>

fn from_iter<I: IntoIterator<Item=&'a Size>>(iterator: I) -> RoaringBitmap<Size>

impl<Size: ExtInt + Halveable> Extend<Size> for RoaringBitmap<Size>

fn extend<I: IntoIterator<Item=Size>>(&mut self, iterator: I)

impl<'a, Size: ExtInt + Halveable + 'a> Extend<&'a Size> for RoaringBitmap<Size>

fn extend<I: IntoIterator<Item=&'a Size>>(&mut self, iterator: I)

impl<Size: ExtInt + Halveable> BitOr<RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn bitor(self, rhs: RoaringBitmap<Size>) -> RoaringBitmap<Size>

Unions the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (2..5u32).collect();
let rb3: RoaringBitmap<u32> = (1..5u32).collect();

let rb4 = rb1 | rb2;

assert_eq!(rb3, rb4);

impl<'a, Size: ExtInt + Halveable> BitOr<&'a RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn bitor(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size>

Unions the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (2..5u32).collect();
let rb3: RoaringBitmap<u32> = (1..5u32).collect();

let rb4 = rb1 | &rb2;

assert_eq!(rb3, rb4);

impl<Size: ExtInt + Halveable> BitAnd<RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn bitand(self, rhs: RoaringBitmap<Size>) -> RoaringBitmap<Size>

Intersects the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (2..5u32).collect();
let rb3: RoaringBitmap<u32> = (2..4u32).collect();

let rb4 = rb1 & rb2;

assert_eq!(rb3, rb4);

impl<'a, Size: ExtInt + Halveable> BitAnd<&'a RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn bitand(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size>

Intersects the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (2..5u32).collect();
let rb3: RoaringBitmap<u32> = (2..4u32).collect();

let rb4 = rb1 & &rb2;

assert_eq!(rb3, rb4);

impl<Size: ExtInt + Halveable> Sub<RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn sub(self, rhs: RoaringBitmap<Size>) -> RoaringBitmap<Size>

Subtracts the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..5u32).collect();
let rb3: RoaringBitmap<u32> = (1..3u32).collect();

let rb4 = rb1 - rb2;

assert_eq!(rb3, rb4);

impl<'a, Size: ExtInt + Halveable> Sub<&'a RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn sub(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size>

Subtracts the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..5u32).collect();
let rb3: RoaringBitmap<u32> = (1..3u32).collect();

let rb4 = rb1 - &rb2;

assert_eq!(rb3, rb4);

impl<Size: ExtInt + Halveable> BitXor<RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn bitxor(self, rhs: RoaringBitmap<Size>) -> RoaringBitmap<Size>

Subtracts the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..6u32).collect();
let rb3: RoaringBitmap<u32> = ((1..3u32).chain(4..6u32)).collect();

let rb4 = rb1 ^ rb2;

assert_eq!(rb3, rb4);

impl<'a, Size: ExtInt + Halveable> BitXor<&'a RoaringBitmap<Size>> for RoaringBitmap<Size>

type Output = RoaringBitmap<Size>

fn bitxor(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size>

Exclusive ors the rhs into this RoaringBitmap.

Examples

use roaring::RoaringBitmap;

let rb1: RoaringBitmap<u32> = (1..4u32).collect();
let rb2: RoaringBitmap<u32> = (3..6u32).collect();
let rb3: RoaringBitmap<u32> = ((1..3u32).chain(4..6u32)).collect();

let rb4 = rb1 ^ &rb2;

assert_eq!(rb3, rb4);

impl<Size: ExtInt + Halveable + Debug> Debug for RoaringBitmap<Size>

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

Derived Implementations

impl<Size: Clone + ExtInt + Halveable> Clone for RoaringBitmap<Size> where <Size as Halveable>::HalfSize: ExtInt

fn clone(&self) -> RoaringBitmap<Size>

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

impl<Size: PartialEq + ExtInt + Halveable> PartialEq for RoaringBitmap<Size> where <Size as Halveable>::HalfSize: ExtInt

fn eq(&self, __arg_0: &RoaringBitmap<Size>) -> bool

fn ne(&self, __arg_0: &RoaringBitmap<Size>) -> bool