use crate::bitset_interface::{bitset_is_empty, bitsets_eq, bitset_contains};
pub(crate) use crate::bitset_interface::LevelMasks;
pub(crate) use crate::bitset_interface::LevelMasksIterExt;
pub use crate::primitive::Primitive;
#[inline]
pub fn is_eq<L, R>(left: L, right: R) -> bool
where
L: LevelMasksIterExt,
R: LevelMasksIterExt<Conf = L::Conf>
{
bitsets_eq(left, right)
}
#[inline]
pub fn is_empty<S: LevelMasksIterExt>(bitset: S) -> bool {
bitset_is_empty(bitset)
}
#[inline]
pub fn contains<S: LevelMasks>(bitset: S, index: usize) -> bool {
bitset_contains(bitset, index)
}
macro_rules! impl_bitset {
(impl <$($generics:tt),*> for $t:ty) => {
impl_bitset!(impl<$($generics),*> for $t where)
};
(impl <$($generics:tt),*> for $t:ty where $($where_bounds:tt)*) => {
unsafe impl<$($generics),*> $crate::BitSetInterface for $t
where
$($where_bounds)*
{}
impl<$($generics),*> IntoIterator for $t
where
$($where_bounds)*
{
type Item = usize;
type IntoIter = $crate::iter::IndexIter<Self>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
$crate::iter::IndexIter::new(self)
}
}
impl<$($generics),*, Rhs> std::ops::BitAnd<Rhs> for $t
where
Rhs: $crate::BitSetInterface<Conf = <Self as BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::And, Self, Rhs>;
#[inline]
fn bitand(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::And, self, rhs)
}
}
impl<$($generics),*, Rhs> std::ops::BitOr<Rhs> for $t
where
Rhs: $crate::BitSetInterface<Conf = <Self as BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::Or, Self, Rhs>;
#[inline]
fn bitor(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::Or, self, rhs)
}
}
impl<$($generics),*, Rhs> std::ops::BitXor<Rhs> for $t
where
Rhs: $crate::BitSetInterface<Conf = <Self as BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::Xor, Self, Rhs>;
#[inline]
fn bitxor(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::Xor, self, rhs)
}
}
impl<$($generics),*, Rhs> std::ops::Sub<Rhs> for $t
where
Rhs: $crate::BitSetInterface<Conf = <Self as BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::Sub, Self, Rhs>;
#[inline]
fn sub(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::Sub, self, rhs)
}
}
impl_bitset!(impl<$($generics),*> for ref $t where $($where_bounds)*);
};
(impl <$($generics:tt),*> for ref $t:ty where $($where_bounds:tt)*) => {
unsafe impl<$($generics),*> $crate::BitSetInterface for &$t
where
$($where_bounds)*
{}
impl<$($generics),*> $t
where
$($where_bounds)*
{
#[inline]
pub fn block_iter<'a>(&'a self) -> $crate::iter::BlockIter<&'a Self>
{
$crate::iter::BlockIter::new(self)
}
#[inline]
pub fn iter<'a>(&'a self) -> $crate::iter::IndexIter<&'a Self>
{
$crate::iter::IndexIter::new(self)
}
#[inline]
pub fn contains(&self, index: usize) -> bool {
$crate::internals::contains(self, index)
}
#[inline]
pub fn is_empty(&self) -> bool {
$crate::internals::is_empty(self)
}
}
impl<$($generics),*> IntoIterator for &$t
where
$($where_bounds)*
{
type Item = usize;
type IntoIter = $crate::iter::IndexIter<Self>;
#[inline]
fn into_iter(self) -> Self::IntoIter {
$crate::iter::IndexIter::new(self)
}
}
impl<$($generics),*,Rhs> PartialEq<Rhs> for $t
where
Rhs: $crate::internals::LevelMasksIterExt<Conf = <Self as $crate::BitSetBase>::Conf>,
$($where_bounds)*
{
#[inline]
fn eq(&self, other: &Rhs) -> bool {
$crate::internals::is_eq(self, other)
}
}
impl<$($generics),*> Eq for $t
where
$($where_bounds)*
{}
impl<$($generics),*> std::fmt::Debug for $t
where
$($where_bounds)*
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.iter()).finish()
}
}
impl<$($generics),*, Rhs> std::ops::BitAnd<Rhs> for &$t
where
Rhs: $crate::BitSetInterface<Conf = <Self as $crate::BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::And, Self, Rhs>;
#[inline]
fn bitand(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::And, self, rhs)
}
}
impl<$($generics),*, Rhs> std::ops::BitOr<Rhs> for &$t
where
Rhs: $crate::BitSetInterface<Conf = <Self as $crate::BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::Or, Self, Rhs>;
#[inline]
fn bitor(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::Or, self, rhs)
}
}
impl<$($generics),*, Rhs> std::ops::BitXor<Rhs> for &$t
where
Rhs: $crate::BitSetInterface<Conf = <Self as $crate::BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::Xor, Self, Rhs>;
#[inline]
fn bitxor(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::Xor, self, rhs)
}
}
impl<$($generics),*, Rhs> std::ops::Sub<Rhs> for &$t
where
Rhs: $crate::BitSetInterface<Conf = <Self as $crate::BitSetBase>::Conf>,
$($where_bounds)*
{
type Output = $crate::Apply<$crate::ops::Sub, Self, Rhs>;
#[inline]
fn sub(self, rhs: Rhs) -> Self::Output{
$crate::apply($crate::ops::Sub, self, rhs)
}
}
};
}
pub(crate) use impl_bitset;