use super::{Bitmap, BitmapIndex, Iter, OwnedBitmap};
use crate::Sealed;
use hwlocality_sys::hwloc_bitmap_s;
#[allow(unused)]
#[cfg(test)]
use similar_asserts::assert_eq;
use std::{
borrow::Borrow,
cmp::Ordering,
fmt::{self, Debug, Display, Formatter, Pointer},
hash::{self, Hash},
marker::PhantomData,
ops::{BitAnd, BitOr, BitXor, Deref, Not, Sub},
ptr::NonNull,
};
#[repr(transparent)]
#[derive(Clone)]
pub struct BitmapRef<'target, Target: OwnedBitmap>(
NonNull<hwloc_bitmap_s>,
PhantomData<&'target Target>,
);
impl<'target, Target: OwnedBitmap> BitmapRef<'target, Target> {
pub(crate) unsafe fn from_nonnull(bitmap: NonNull<hwloc_bitmap_s>) -> Self {
Self(bitmap, PhantomData)
}
pub fn clone_target(&self) -> Target {
self.as_ref().clone()
}
pub(crate) fn cast<Other: OwnedBitmap>(self) -> BitmapRef<'target, Other> {
BitmapRef(self.0, PhantomData)
}
}
impl<Target: OwnedBitmap> AsRef<Target> for BitmapRef<'_, Target> {
fn as_ref(&self) -> &Target {
unsafe {
let ptr: *const Self = self;
&*ptr.cast::<Target>()
}
}
}
impl<Target, Rhs> BitAnd<Rhs> for &BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: BitAnd<&'b Target, Output = Target>,
{
type Output = Target;
fn bitand(self, rhs: Rhs) -> Target {
self.as_ref() & rhs.borrow()
}
}
impl<Target, Rhs> BitAnd<Rhs> for BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: BitAnd<&'b Target, Output = Target>,
{
type Output = Target;
fn bitand(self, rhs: Rhs) -> Target {
self.as_ref() & rhs.borrow()
}
}
impl<Target, Rhs> BitOr<Rhs> for &BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: BitOr<&'b Target, Output = Target>,
{
type Output = Target;
fn bitor(self, rhs: Rhs) -> Target {
self.as_ref() | rhs.borrow()
}
}
impl<Target, Rhs> BitOr<Rhs> for BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: BitOr<&'b Target, Output = Target>,
{
type Output = Target;
fn bitor(self, rhs: Rhs) -> Target {
self.as_ref() | rhs.borrow()
}
}
impl<Target, Rhs> BitXor<Rhs> for &BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: BitXor<&'b Target, Output = Target>,
{
type Output = Target;
fn bitxor(self, rhs: Rhs) -> Target {
self.as_ref() ^ rhs.borrow()
}
}
impl<Target, Rhs> BitXor<Rhs> for BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: BitXor<&'b Target, Output = Target>,
{
type Output = Target;
fn bitxor(self, rhs: Rhs) -> Target {
self.as_ref() ^ rhs.borrow()
}
}
#[doc(hidden)]
impl<Target: OwnedBitmap> Borrow<Target> for &BitmapRef<'_, Target> {
fn borrow(&self) -> &Target {
self.as_ref()
}
}
impl<Target: OwnedBitmap> Borrow<Target> for BitmapRef<'_, Target> {
fn borrow(&self) -> &Target {
self.as_ref()
}
}
impl<Target: OwnedBitmap> Copy for BitmapRef<'_, Target> {}
impl<Target: OwnedBitmap + Debug> Debug for BitmapRef<'_, Target> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
<Target as Debug>::fmt(self.as_ref(), f)
}
}
impl<Target: OwnedBitmap> Deref for BitmapRef<'_, Target> {
type Target = Target;
fn deref(&self) -> &Target {
self.as_ref()
}
}
impl<Target: OwnedBitmap + Display> Display for BitmapRef<'_, Target> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
<Target as Display>::fmt(self.as_ref(), f)
}
}
impl<Target: OwnedBitmap + Eq + PartialEq<Self>> Eq for BitmapRef<'_, Target> {}
impl<'target, Target: OwnedBitmap> From<&'target Target> for BitmapRef<'target, Target> {
fn from(input: &'target Target) -> Self {
Self(unsafe { input.inner() }, PhantomData)
}
}
impl<Target: OwnedBitmap + Hash> Hash for BitmapRef<'_, Target> {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.as_ref().hash(state)
}
}
impl<'target, 'self_, Target> IntoIterator for &'self_ BitmapRef<'target, Target>
where
'target: 'self_,
Target: OwnedBitmap,
&'self_ Target: Borrow<Bitmap>,
{
type Item = BitmapIndex;
type IntoIter = Iter<&'self_ Target>;
fn into_iter(self) -> Self::IntoIter {
Iter::new(self.as_ref(), Bitmap::next_set)
}
}
impl<'target, Target: OwnedBitmap> IntoIterator for BitmapRef<'target, Target> {
type Item = BitmapIndex;
type IntoIter = Iter<BitmapRef<'target, Bitmap>>;
fn into_iter(self) -> Self::IntoIter {
Iter::new(self.cast(), Bitmap::next_set)
}
}
impl<Target> Not for &BitmapRef<'_, Target>
where
Target: OwnedBitmap,
for<'target> &'target Target: Not<Output = Target>,
{
type Output = Target;
fn not(self) -> Target {
!(self.as_ref())
}
}
impl<Target> Not for BitmapRef<'_, Target>
where
Target: OwnedBitmap,
for<'target> &'target Target: Not<Output = Target>,
{
type Output = Target;
fn not(self) -> Target {
!(self.as_ref())
}
}
impl<Target: OwnedBitmap + Ord + PartialOrd<Self>> Ord for BitmapRef<'_, Target> {
fn cmp(&self, other: &Self) -> Ordering {
self.as_ref().cmp(other.as_ref())
}
}
impl<Target, Rhs> PartialEq<Rhs> for BitmapRef<'_, Target>
where
Target: OwnedBitmap + PartialEq<Rhs>,
{
fn eq(&self, other: &Rhs) -> bool {
self.as_ref() == other
}
}
impl<Target, Rhs> PartialOrd<Rhs> for BitmapRef<'_, Target>
where
Target: OwnedBitmap + PartialOrd<Rhs>,
{
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering> {
self.as_ref().partial_cmp(other)
}
}
impl<Target: OwnedBitmap> Pointer for BitmapRef<'_, Target> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
<NonNull<hwloc_bitmap_s> as fmt::Pointer>::fmt(&self.0, f)
}
}
impl<Target: OwnedBitmap> Sealed for BitmapRef<'_, Target> {}
unsafe impl<Target: OwnedBitmap + Sync> Send for BitmapRef<'_, Target> {}
impl<Target, Rhs> Sub<Rhs> for &BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: Sub<&'b Target, Output = Target>,
{
type Output = Target;
fn sub(self, rhs: Rhs) -> Target {
self.as_ref() - rhs.borrow()
}
}
impl<Target, Rhs> Sub<Rhs> for BitmapRef<'_, Target>
where
Target: OwnedBitmap,
Rhs: Borrow<Target>,
for<'a, 'b> &'a Target: Sub<&'b Target, Output = Target>,
{
type Output = Target;
fn sub(self, rhs: Rhs) -> Target {
self.as_ref() - rhs.borrow()
}
}
unsafe impl<Target: OwnedBitmap + Sync> Sync for BitmapRef<'_, Target> {}
#[macro_export]
#[doc(hidden)]
macro_rules! impl_bitmap_newtype_ref {
(
$(#[$attr:meta])*
$newtype:ident
) => {
impl<'target> AsRef<Bitmap> for BitmapRef<'_, $newtype> {
fn as_ref(&self) -> &Bitmap {
let newtype: &$newtype = self.as_ref();
newtype.as_ref()
}
}
#[doc(hidden)]
impl Borrow<Bitmap> for &$newtype {
fn borrow(&self) -> &Bitmap {
self.as_ref()
}
}
impl<'target> Borrow<Bitmap> for BitmapRef<'_, $newtype> {
fn borrow(&self) -> &Bitmap {
self.as_ref()
}
}
impl<'target> From<BitmapRef<'target, Bitmap>> for BitmapRef<'target, $newtype> {
fn from(input: BitmapRef<'target, Bitmap>) -> Self {
input.cast()
}
}
impl<'target> From<BitmapRef<'target, $newtype>> for BitmapRef<'target, Bitmap> {
fn from(input: BitmapRef<'target, $newtype>) -> Self {
input.cast()
}
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! impl_bitmap_newtype_ref_tests {
(
$(#[$attr:meta])*
$newtype:ident
) => {
use $crate::bitmap;
assert_impl_all!($newtype:
BitAnd<BitmapRef<'static, $newtype>>,
BitAnd<&'static BitmapRef<'static, $newtype>>,
BitAndAssign<BitmapRef<'static, $newtype>>,
BitAndAssign<&'static BitmapRef<'static, $newtype>>,
BitOr<BitmapRef<'static, $newtype>>,
BitOr<&'static BitmapRef<'static, $newtype>>,
BitOrAssign<BitmapRef<'static, $newtype>>,
BitOrAssign<&'static BitmapRef<'static, $newtype>>,
BitXor<BitmapRef<'static, $newtype>>,
BitXor<&'static BitmapRef<'static, $newtype>>,
BitXorAssign<BitmapRef<'static, $newtype>>,
BitXorAssign<&'static BitmapRef<'static, $newtype>>,
PartialEq<BitmapRef<'static, $newtype>>,
PartialEq<&'static BitmapRef<'static, $newtype>>,
PartialOrd<BitmapRef<'static, $newtype>>,
PartialOrd<&'static BitmapRef<'static, $newtype>>,
Sub<BitmapRef<'static, $newtype>>,
Sub<&'static BitmapRef<'static, $newtype>>,
SubAssign<BitmapRef<'static, $newtype>>,
SubAssign<&'static BitmapRef<'static, $newtype>>,
);
assert_impl_all!(&$newtype:
BitAnd<BitmapRef<'static, $newtype>>,
BitAnd<&'static BitmapRef<'static, $newtype>>,
BitOr<BitmapRef<'static, $newtype>>,
BitOr<&'static BitmapRef<'static, $newtype>>,
BitXor<BitmapRef<'static, $newtype>>,
BitXor<&'static BitmapRef<'static, $newtype>>,
Sub<BitmapRef<'static, $newtype>>,
Sub<&'static BitmapRef<'static, $newtype>>,
);
assert_impl_all!(BitmapRef<'static, $newtype>:
AsRef<$newtype>, AsRef<Bitmap>,
BitAnd<$newtype>, BitAnd<&'static $newtype>,
BitAnd<BitmapRef<'static, $newtype>>,
BitAnd<&'static BitmapRef<'static, $newtype>>,
BitOr<$newtype>, BitOr<&'static $newtype>,
BitOr<BitmapRef<'static, $newtype>>,
BitOr<&'static BitmapRef<'static, $newtype>>,
BitXor<$newtype>, BitXor<&'static $newtype>,
BitXor<BitmapRef<'static, $newtype>>,
BitXor<&'static BitmapRef<'static, $newtype>>,
Borrow<$newtype>, Borrow<Bitmap>, Copy, Debug,
Deref<Target=$newtype>, Display, Eq, From<&'static $newtype>,
Hash, Into<BitmapRef<'static, Bitmap>>,
IntoIterator<Item=BitmapIndex>, Not<Output=$newtype>, Ord,
PartialEq<&'static $newtype>,
PartialEq<BitmapRef<'static, $newtype>>,
PartialEq<&'static BitmapRef<'static, $newtype>>,
PartialOrd<&'static $newtype>,
PartialOrd<BitmapRef<'static, $newtype>>,
PartialOrd<&'static BitmapRef<'static, $newtype>>,
Pointer, Sized, SpecializedBitmapRef<Owned=$newtype>,
Sub<$newtype>, Sub<&'static $newtype>,
Sub<BitmapRef<'static, $newtype>>,
Sub<&'static BitmapRef<'static, $newtype>>,
Sync, Unpin, UnwindSafe
);
assert_not_impl_any!(BitmapRef<'_, $newtype>:
Binary, Default, Drop, Error, LowerExp, LowerHex, Octal, Read,
UpperExp, UpperHex, fmt::Write, io::Write
);
assert_impl_all!(&BitmapRef<'static, $newtype>:
BitAnd<$newtype>, BitAnd<&'static $newtype>,
BitAnd<BitmapRef<'static, $newtype>>,
BitAnd<&'static BitmapRef<'static, $newtype>>,
BitOr<$newtype>, BitOr<&'static $newtype>,
BitOr<BitmapRef<'static, $newtype>>,
BitOr<&'static BitmapRef<'static, $newtype>>,
BitXor<$newtype>, BitXor<&'static $newtype>,
BitXor<BitmapRef<'static, $newtype>>,
BitXor<&'static BitmapRef<'static, $newtype>>,
IntoIterator<Item=BitmapIndex>,
Not<Output=$newtype>,
Sub<$newtype>, Sub<&'static $newtype>,
Sub<BitmapRef<'static, $newtype>>,
Sub<&'static BitmapRef<'static, $newtype>>,
);
#[test]
fn static_checks_newtype() {
assert_eq!(
<$newtype as SpecializedBitmap>::BITMAP_KIND,
BitmapKind::$newtype
);
}
fn test_newtype_ref_unary(
new: &$newtype,
new_ref: BitmapRef<'_, $newtype>
) -> Result<(), TestCaseError> {
let clone: $newtype = new_ref.clone_target();
prop_assert_eq!(clone, new);
prop_assert_eq!(
<BitmapRef<'_, _> as AsRef<$newtype>>::as_ref(&new_ref).as_ptr(),
new.as_ptr()
);
prop_assert_eq!(
<BitmapRef<'_, _> as AsRef<Bitmap>>::as_ref(&new_ref).as_ptr(),
new.as_ptr()
);
prop_assert_eq!(
<BitmapRef<'_, _> as Borrow<$newtype>>::borrow(&new_ref).as_ptr(),
new.as_ptr()
);
prop_assert_eq!(
<BitmapRef<'_, _> as Borrow<Bitmap>>::borrow(&new_ref).as_ptr(),
new.as_ptr()
);
prop_assert_eq!(
<&BitmapRef<'_, _> as Borrow<$newtype>>::borrow(&&new_ref).as_ptr(),
new.as_ptr()
);
prop_assert_eq!(
<BitmapRef<'_, _> as Deref>::deref(&new_ref).as_ptr(),
new.as_ptr()
);
let bitmap_ref = BitmapRef::<Bitmap>::from(new_ref);
prop_assert_eq!(bitmap_ref.as_ptr(), new_ref.as_ptr());
let new_ref2 = BitmapRef::<$newtype>::from(bitmap_ref);
prop_assert_eq!(new_ref2.as_ptr(), new_ref.as_ptr());
prop_assert_eq!(format!("{new:?}"), format!("{new_ref:?}"));
prop_assert_eq!(new.to_string(), new_ref.to_string());
let state = RandomState::new();
prop_assert_eq!(state.hash_one(new), state.hash_one(new_ref));
prop_assert_eq!(format!("{:p}", new.as_ptr()), format!("{new_ref:p}"));
bitmap::allow_infinite_iteration(|| {
prop_assert!(new
.iter_set()
.take(INFINITE_EXPLORE_ITERS)
.eq(new_ref.into_iter().take(INFINITE_EXPLORE_ITERS)));
prop_assert!(new
.iter_set()
.take(INFINITE_EXPLORE_ITERS)
.eq((&new_ref).into_iter().take(INFINITE_EXPLORE_ITERS)));
Ok(())
})?;
prop_assert_eq!(!new, !new_ref);
prop_assert_eq!(!new, !&new_ref);
Ok(())
}
fn test_newtype_ref_binops([new1, new2]: [$newtype; 2]) -> Result<(), TestCaseError> {
let new1_ref = BitmapRef::from(&new1);
prop_assert_eq!(new1_ref & &new2, &new1 & &new2);
prop_assert_eq!(&new1_ref & &new2, &new1 & &new2);
prop_assert_eq!(new1_ref | &new2, &new1 | &new2);
prop_assert_eq!(&new1_ref | &new2, &new1 | &new2);
prop_assert_eq!(new1_ref ^ &new2, &new1 ^ &new2);
prop_assert_eq!(&new1_ref ^ &new2, &new1 ^ &new2);
prop_assert_eq!(new1_ref - &new2, &new1 - &new2);
prop_assert_eq!(&new1_ref - &new2, &new1 - &new2);
prop_assert_eq!(new1_ref == &new2, &new1 == &new2);
prop_assert_eq!(new1_ref.partial_cmp(&new2), new1.partial_cmp(&new2));
prop_assert_eq!(new1_ref.cmp(&BitmapRef::from(&new2)), new1.cmp(&new2));
Ok(())
}
};
}
#[allow(clippy::cognitive_complexity, clippy::op_ref, clippy::too_many_lines)]
#[cfg(test)]
pub(super) mod tests {
use super::*;
use crate::bitmap::{self, tests::INFINITE_EXPLORE_ITERS};
use proptest::prelude::*;
#[allow(unused)]
use similar_asserts::assert_eq;
use static_assertions::{
assert_eq_align, assert_eq_size, assert_impl_all, assert_not_impl_any,
};
use std::{
collections::hash_map::RandomState,
error::Error,
fmt::{Binary, LowerExp, LowerHex, Octal, UpperExp, UpperHex},
hash::BuildHasher,
io::{self, Read},
ops::{BitAndAssign, BitOrAssign, BitXorAssign, SubAssign},
panic::UnwindSafe,
};
assert_impl_all!(Bitmap:
BitAnd<BitmapRef<'static, Bitmap>>,
BitAnd<&'static BitmapRef<'static, Bitmap>>,
BitAndAssign<BitmapRef<'static, Bitmap>>,
BitAndAssign<&'static BitmapRef<'static, Bitmap>>,
BitOr<BitmapRef<'static, Bitmap>>,
BitOr<&'static BitmapRef<'static, Bitmap>>,
BitOrAssign<BitmapRef<'static, Bitmap>>,
BitOrAssign<&'static BitmapRef<'static, Bitmap>>,
BitXor<BitmapRef<'static, Bitmap>>,
BitXor<&'static BitmapRef<'static, Bitmap>>,
BitXorAssign<BitmapRef<'static, Bitmap>>,
BitXorAssign<&'static BitmapRef<'static, Bitmap>>,
PartialEq<BitmapRef<'static, Bitmap>>,
PartialEq<&'static BitmapRef<'static, Bitmap>>,
PartialOrd<BitmapRef<'static, Bitmap>>,
PartialOrd<&'static BitmapRef<'static, Bitmap>>,
Sub<BitmapRef<'static, Bitmap>>,
Sub<&'static BitmapRef<'static, Bitmap>>,
SubAssign<BitmapRef<'static, Bitmap>>,
SubAssign<&'static BitmapRef<'static, Bitmap>>,
);
assert_impl_all!(&Bitmap:
BitAnd<BitmapRef<'static, Bitmap>>,
BitAnd<&'static BitmapRef<'static, Bitmap>>,
BitOr<BitmapRef<'static, Bitmap>>,
BitOr<&'static BitmapRef<'static, Bitmap>>,
BitXor<BitmapRef<'static, Bitmap>>,
BitXor<&'static BitmapRef<'static, Bitmap>>,
Sub<BitmapRef<'static, Bitmap>>,
Sub<&'static BitmapRef<'static, Bitmap>>,
);
assert_eq_align!(BitmapRef<'static, Bitmap>, NonNull<hwloc_bitmap_s>);
assert_eq_size!(BitmapRef<'static, Bitmap>, NonNull<hwloc_bitmap_s>);
assert_impl_all!(BitmapRef<'static, Bitmap>:
AsRef<Bitmap>,
BitAnd<Bitmap>, BitAnd<&'static Bitmap>,
BitAnd<BitmapRef<'static, Bitmap>>,
BitAnd<&'static BitmapRef<'static, Bitmap>>,
BitOr<Bitmap>, BitOr<&'static Bitmap>,
BitOr<BitmapRef<'static, Bitmap>>,
BitOr<&'static BitmapRef<'static, Bitmap>>,
BitXor<Bitmap>, BitXor<&'static Bitmap>,
BitXor<BitmapRef<'static, Bitmap>>,
BitXor<&'static BitmapRef<'static, Bitmap>>,
Borrow<Bitmap>, Copy, Debug, Deref<Target=Bitmap>, Display,
From<&'static Bitmap>, Hash, IntoIterator<Item=BitmapIndex>,
Not<Output=Bitmap>, Ord,
PartialEq<&'static Bitmap>,
PartialEq<BitmapRef<'static, Bitmap>>,
PartialEq<&'static BitmapRef<'static, Bitmap>>,
PartialOrd<&'static Bitmap>,
PartialOrd<BitmapRef<'static, Bitmap>>,
PartialOrd<&'static BitmapRef<'static, Bitmap>>,
Pointer, Sized,
Sub<Bitmap>, Sub<&'static Bitmap>,
Sub<BitmapRef<'static, Bitmap>>,
Sub<&'static BitmapRef<'static, Bitmap>>,
Sync, Unpin, UnwindSafe
);
assert_not_impl_any!(BitmapRef<'_, Bitmap>:
Binary, Default, Drop, Error, LowerExp, LowerHex, Octal, Read, UpperExp,
UpperHex, fmt::Write, io::Write
);
assert_impl_all!(&BitmapRef<'static, Bitmap>:
BitAnd<Bitmap>, BitAnd<&'static Bitmap>,
BitAnd<BitmapRef<'static, Bitmap>>,
BitAnd<&'static BitmapRef<'static, Bitmap>>,
BitOr<Bitmap>, BitOr<&'static Bitmap>,
BitOr<BitmapRef<'static, Bitmap>>,
BitOr<&'static BitmapRef<'static, Bitmap>>,
BitXor<Bitmap>, BitXor<&'static Bitmap>,
BitXor<BitmapRef<'static, Bitmap>>,
BitXor<&'static BitmapRef<'static, Bitmap>>,
IntoIterator<Item=BitmapIndex>,
Not<Output=Bitmap>,
Sub<Bitmap>, Sub<&'static Bitmap>,
Sub<BitmapRef<'static, Bitmap>>,
Sub<&'static BitmapRef<'static, Bitmap>>,
);
pub(crate) fn test_bitmap_ref_unary(
bitmap: &Bitmap,
bitmap_ref: BitmapRef<'_, Bitmap>,
) -> Result<(), TestCaseError> {
let clone: Bitmap = bitmap_ref.clone_target();
prop_assert_eq!(clone, bitmap);
prop_assert_eq!(
<BitmapRef<'_, _> as AsRef<Bitmap>>::as_ref(&bitmap_ref).as_ptr(),
bitmap.as_ptr()
);
prop_assert_eq!(
<BitmapRef<'_, _> as Borrow<Bitmap>>::borrow(&bitmap_ref).as_ptr(),
bitmap.as_ptr()
);
prop_assert_eq!(
<&BitmapRef<'_, _> as Borrow<Bitmap>>::borrow(&&bitmap_ref).as_ptr(),
bitmap.as_ptr()
);
prop_assert_eq!(
<BitmapRef<'_, _> as Deref>::deref(&bitmap_ref).as_ptr(),
bitmap.as_ptr()
);
prop_assert_eq!(format!("{bitmap:?}"), format!("{bitmap_ref:?}"));
prop_assert_eq!(bitmap.to_string(), bitmap_ref.to_string());
let state = RandomState::new();
prop_assert_eq!(state.hash_one(bitmap), state.hash_one(bitmap_ref));
prop_assert_eq!(format!("{:p}", bitmap.0), format!("{bitmap_ref:p}"));
bitmap::allow_infinite_iteration(|| {
prop_assert!(
bitmap
.iter_set()
.take(INFINITE_EXPLORE_ITERS)
.eq(bitmap_ref.into_iter().take(INFINITE_EXPLORE_ITERS))
);
prop_assert!(
bitmap
.iter_set()
.take(INFINITE_EXPLORE_ITERS)
.eq((&bitmap_ref).into_iter().take(INFINITE_EXPLORE_ITERS))
);
Ok(())
})?;
prop_assert_eq!(!bitmap, !bitmap_ref);
prop_assert_eq!(!bitmap, !&bitmap_ref);
Ok(())
}
pub(crate) fn test_bitmap_ref_binops(
bitmap: &Bitmap,
other: &Bitmap,
) -> Result<(), TestCaseError> {
let bitmap_ref = BitmapRef::from(bitmap);
prop_assert_eq!(bitmap_ref & other, bitmap & other);
prop_assert_eq!(&bitmap_ref & other, bitmap & other);
prop_assert_eq!(bitmap_ref | other, bitmap | other);
prop_assert_eq!(&bitmap_ref | other, bitmap | other);
prop_assert_eq!(bitmap_ref ^ other, bitmap ^ other);
prop_assert_eq!(&bitmap_ref ^ other, bitmap ^ other);
prop_assert_eq!(bitmap_ref - other, bitmap - other);
prop_assert_eq!(&bitmap_ref - other, bitmap - other);
prop_assert_eq!(bitmap_ref == other, bitmap == other);
prop_assert_eq!(bitmap_ref.partial_cmp(other), bitmap.partial_cmp(other));
prop_assert_eq!(bitmap_ref.cmp(&BitmapRef::from(other)), bitmap.cmp(other));
Ok(())
}
}