use pigeonhole_format::roaring;
#[derive(Debug, Clone, Copy)]
pub struct SetRef<'a>(roaring::SetRef<'a>);
impl<'a> SetRef<'a> {
pub fn from_bytes(bytes: &'a [u8]) -> Option<Self> {
roaring::SetRef::parse(bytes).ok().map(Self)
}
pub fn as_bytes(&self) -> &'a [u8] {
self.0.as_bytes()
}
pub fn len(&self) -> u64 {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn contains(&self, x: u32) -> bool {
self.0.contains(x)
}
pub fn iter(&self) -> SetIter<'a> {
SetIter(self.0.iter())
}
pub fn intersection<'b>(&self, other: &SetRef<'b>) -> SetIntersection<'a, 'b> {
SetIntersection(self.0.intersection(&other.0))
}
pub fn intersection_len(&self, other: &SetRef<'_>) -> u64 {
self.0.intersection_len(&other.0)
}
pub fn union_len(&self, other: &SetRef<'_>) -> u64 {
self.0.union_len(&other.0)
}
}
pub struct SetIter<'a>(roaring::Iter<'a>);
impl Iterator for SetIter<'_> {
type Item = u32;
fn next(&mut self) -> Option<u32> {
self.0.next()
}
}
pub struct SetIntersection<'a, 'b>(roaring::Intersection<'a, 'b>);
impl Iterator for SetIntersection<'_, '_> {
type Item = u32;
fn next(&mut self) -> Option<u32> {
self.0.next()
}
}