1
0
Fork 0

const lookup table

This commit is contained in:
Paul-Nicolas Madelaine 2025-10-22 22:59:53 +02:00
parent 752150107e
commit 0d22c59cc3
8 changed files with 573 additions and 542 deletions

View file

@ -18,7 +18,7 @@ impl Bitboard {
}
#[inline]
pub fn first(&self) -> Option<Square> {
pub const fn first(&self) -> Option<Square> {
let mask = self.0;
match mask {
0 => None,
@ -26,6 +26,17 @@ impl Bitboard {
}
}
#[inline]
pub const fn last(&self) -> Option<Square> {
let mask = self.0;
match mask {
0 => None,
_ => {
Some(unsafe { Square::transmute(63_u8.unchecked_sub(mask.leading_zeros() as u8)) })
}
}
}
#[inline]
pub fn pop(&mut self) -> Option<Square> {
let Self(ref mut mask) = self;
@ -38,7 +49,7 @@ impl Bitboard {
}
#[inline]
pub fn insert(&mut self, square: Square) {
pub const fn insert(&mut self, square: Square) {
self.0 |= 1 << square as u8;
}
@ -57,7 +68,7 @@ impl Bitboard {
}
#[inline]
pub fn contains(&self, square: Square) -> bool {
pub const fn contains(&self, square: Square) -> bool {
self.0 & (1 << square as u8) != 0
}