#![warn(missing_docs)]
#![warn(variant_size_differences)]
extern crate num;
use std::fmt::{ Debug, Formatter, Result };
use std::ops::{ BitXor, BitAnd, BitOr, Sub };
use std::iter::{ IntoIterator, FromIterator };
use util::{ Halveable, ExtInt };
pub use iter::{ Iter, UnionIter, IntersectionIter, DifferenceIter, SymmetricDifferenceIter };
mod imp;
mod util;
mod iter;
mod store;
mod container;
#[derive(PartialEq, Clone)]
pub struct RoaringBitmap<Size: ExtInt + Halveable> where <Size as Halveable>::HalfSize: ExtInt {
containers: Vec<container::Container<<Size as Halveable>::HalfSize>>,
}
impl<Size: ExtInt + Halveable> RoaringBitmap<Size> {
#[inline]
pub fn new() -> Self {
imp::new()
}
#[inline]
pub fn insert(&mut self, value: Size) -> bool {
imp::insert(self, value)
}
#[inline]
pub fn remove(&mut self, value: Size) -> bool {
imp::remove(self, value)
}
#[inline]
pub fn contains(&self, value: Size) -> bool {
imp::contains(self, value)
}
#[inline]
pub fn clear(&mut self) {
imp::clear(self)
}
#[inline]
pub fn is_empty(&self) -> bool {
imp::is_empty(self)
}
#[inline]
pub fn len(&self) -> Size {
imp::len(self)
}
#[inline]
pub fn iter<'a>(&'a self) -> Iter<'a, Size> where <Size as Halveable>::HalfSize : 'a {
imp::iter(self)
}
#[inline]
pub fn is_disjoint(&self, other: &Self) -> bool {
imp::is_disjoint(self, other)
}
#[inline]
pub fn is_subset(&self, other: &Self) -> bool {
imp::is_subset(self, other)
}
#[inline]
pub fn is_superset(&self, other: &Self) -> bool {
imp::is_superset(self, other)
}
#[inline]
pub fn union<'a>(&'a self, other: &'a Self) -> UnionIter<'a, Size> where <Size as Halveable>::HalfSize : 'a {
imp::union(self, other)
}
#[inline]
pub fn intersection<'a>(&'a self, other: &'a Self) -> IntersectionIter<'a, Size> where <Size as Halveable>::HalfSize : 'a {
imp::intersection(self, other)
}
#[inline]
pub fn difference<'a>(&'a self, other: &'a Self) -> DifferenceIter<'a, Size> where <Size as Halveable>::HalfSize : 'a {
imp::difference(self, other)
}
#[inline]
pub fn symmetric_difference<'a>(&'a self, other: &'a Self) -> SymmetricDifferenceIter<'a, Size> where <Size as Halveable>::HalfSize : 'a {
imp::symmetric_difference(self, other)
}
#[inline]
pub fn union_with(&mut self, other: &Self) {
imp::union_with(self, other)
}
#[inline]
pub fn intersect_with(&mut self, other: &Self) {
imp::intersect_with(self, other)
}
#[inline]
pub fn difference_with(&mut self, other: &Self) {
imp::difference_with(self, other)
}
#[inline]
pub fn symmetric_difference_with(&mut self, other: &Self) {
imp::symmetric_difference_with(self, other)
}
}
impl<Size: ExtInt + Halveable> IntoIterator for RoaringBitmap<Size> {
type Item = Size;
type IntoIter = <Vec<Size> as IntoIterator>::IntoIter;
#[inline]
fn into_iter(self) -> <Self as IntoIterator>::IntoIter {
imp::iter(&self).collect::<Vec<Size>>().into_iter()
}
}
impl<Size: ExtInt + Halveable> FromIterator<Size> for RoaringBitmap<Size> {
#[inline]
fn from_iter<I: IntoIterator<Item = Size>>(iterator: I) -> Self {
imp::from_iter(iterator)
}
}
impl<'a, Size: ExtInt + Halveable + 'a> FromIterator<&'a Size> for RoaringBitmap<Size> {
#[inline]
fn from_iter<I: IntoIterator<Item = &'a Size>>(iterator: I) -> Self {
imp::from_iter_ref(iterator)
}
}
impl<Size: ExtInt + Halveable> Extend<Size> for RoaringBitmap<Size> {
#[inline]
fn extend<I: IntoIterator<Item = Size>>(&mut self, iterator: I) {
imp::extend(self, iterator)
}
}
impl<'a, Size: ExtInt + Halveable + 'a> Extend<&'a Size> for RoaringBitmap<Size> {
#[inline]
fn extend<I: IntoIterator<Item = &'a Size>>(&mut self, iterator: I) {
imp::extend_ref(self, iterator)
}
}
impl<Size: ExtInt + Halveable> BitOr<RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = Self;
#[inline]
fn bitor(mut self, rhs: Self) -> Self {
self.union_with(&rhs);
self
}
}
impl<'a, Size: ExtInt + Halveable> BitOr<RoaringBitmap<Size>> for &'a RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn bitor(self, mut rhs: RoaringBitmap<Size>) -> RoaringBitmap<Size> {
rhs.union_with(self);
rhs
}
}
impl<'a, 'b, Size: ExtInt + Halveable> BitOr<&'a RoaringBitmap<Size>> for &'b RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn bitor(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size> {
let mut result = self.clone();
result.union_with(rhs);
result
}
}
impl<'a, Size: ExtInt + Halveable> BitOr<&'a RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = Self;
#[inline]
fn bitor(mut self, rhs: &'a Self) -> Self {
self.union_with(rhs);
self
}
}
impl<Size: ExtInt + Halveable> BitAnd<RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = Self;
#[inline]
fn bitand(mut self, rhs: Self) -> Self {
self.intersect_with(&rhs);
self
}
}
impl<'a, Size: ExtInt + Halveable> BitAnd<&'a RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = Self;
#[inline]
fn bitand(mut self, rhs: &'a Self) -> Self {
self.intersect_with(rhs);
self
}
}
impl<'a, Size: ExtInt + Halveable> BitAnd<RoaringBitmap<Size>> for &'a RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn bitand(self, mut rhs: RoaringBitmap<Size>) -> RoaringBitmap<Size> {
rhs.intersect_with(self);
rhs
}
}
impl<'a, 'b, Size: ExtInt + Halveable> BitAnd<&'a RoaringBitmap<Size>> for &'b RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn bitand(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size> {
let mut result = self.clone();
result.intersect_with(rhs);
result
}
}
impl<Size: ExtInt + Halveable> Sub<RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = Self;
#[inline]
fn sub(mut self, rhs: Self) -> Self {
self.difference_with(&rhs);
self
}
}
impl<'a, Size: ExtInt + Halveable> Sub<&'a RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = Self;
#[inline]
fn sub(mut self, rhs: &'a Self) -> Self {
self.difference_with(rhs);
self
}
}
impl<'a, 'b, Size: ExtInt + Halveable> Sub<&'a RoaringBitmap<Size>> for &'b RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn sub(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size> {
let mut result = self.clone();
result.difference_with(rhs);
result
}
}
impl<Size: ExtInt + Halveable> BitXor<RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = Self;
#[inline]
fn bitxor(mut self, rhs: Self) -> Self {
self.symmetric_difference_with(&rhs);
self
}
}
impl<'a, Size: ExtInt + Halveable> BitXor<&'a RoaringBitmap<Size>> for RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn bitxor(mut self, rhs: &'a Self) -> Self {
self.symmetric_difference_with(rhs);
self
}
}
impl<'a, Size: ExtInt + Halveable> BitXor<RoaringBitmap<Size>> for &'a RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn bitxor(self, mut rhs: RoaringBitmap<Size>) -> RoaringBitmap<Size> {
rhs.symmetric_difference_with(self);
rhs
}
}
impl<'a, 'b, Size: ExtInt + Halveable> BitXor<&'a RoaringBitmap<Size>> for &'b RoaringBitmap<Size> {
type Output = RoaringBitmap<Size>;
#[inline]
fn bitxor(self, rhs: &'a RoaringBitmap<Size>) -> RoaringBitmap<Size> {
let mut result = self.clone();
result.symmetric_difference_with(rhs);
result
}
}
impl<Size: ExtInt + Halveable + Debug> Debug for RoaringBitmap<Size> {
#[inline]
fn fmt(&self, formatter: &mut Formatter) -> Result {
if self.len() < util::cast(16u8) {
format!("RoaringBitmap<{:?}>", self.iter().collect::<Vec<Size>>()).fmt(formatter)
} else {
format!("RoaringBitmap<{:?} values between {:?} and {:?}>", self.len(), imp::min(self), imp::max(self)).fmt(formatter)
}
}
}