1
0
Fork 0

misc bitboard implementation

This commit is contained in:
Paul-Nicolas Madelaine 2025-11-29 14:12:20 +01:00
parent e44ddca8e1
commit 57b78880f2

View file

@ -157,18 +157,6 @@ impl Iterator for Bitboard {
(len, Some(len)) (len, Some(len))
} }
#[inline] #[inline]
fn for_each<F>(self, mut f: F)
where
Self: Sized,
F: FnMut(Self::Item),
{
let mut mask = self.0;
while mask != 0 {
f(unsafe { Square::new_unchecked(mask.trailing_zeros() as u8) });
mask &= mask.wrapping_sub(1);
}
}
#[inline]
fn fold<B, F>(self, init: B, mut f: F) -> B fn fold<B, F>(self, init: B, mut f: F) -> B
where where
Self: Sized, Self: Sized,
@ -184,6 +172,14 @@ impl Iterator for Bitboard {
} }
acc acc
} }
#[inline]
fn for_each<F>(self, mut f: F)
where
Self: Sized,
F: FnMut(Self::Item),
{
self.fold((), |_, square| f(square));
}
} }
impl core::iter::FusedIterator for Bitboard {} impl core::iter::FusedIterator for Bitboard {}
impl core::iter::ExactSizeIterator for Bitboard { impl core::iter::ExactSizeIterator for Bitboard {