use proper type for bitboard indexing

This commit is contained in:
2025-02-28 18:52:44 -05:00
parent 72b146db55
commit 7b5f84bcb2

View File

@@ -1,6 +1,6 @@
use super::{
board::Board,
coords::{CoordAxis, CoordPair},
coords::{CoordPair, CoordPairInner},
};
use const_fn::const_fn;
use static_assertions::const_assert;
@@ -53,24 +53,24 @@ impl BitBoard {
}
#[cfg(not(feature = "bitvec"))]
const fn get_by_index(&self, index: CoordAxis) -> bool {
const fn get_by_index(&self, index: CoordPairInner) -> bool {
((self.0 >> index) & 0b1) != 0b0
}
#[cfg(not(feature = "bitvec"))]
const fn set_by_index(&mut self, index: CoordAxis, value: bool) {
const fn set_by_index(&mut self, index: CoordPairInner, value: bool) {
// PERF! branchless setting of bit (~+3% perf bump)
self.0 &= !(0b1 << index); // clear bit
self.0 |= (value as BitBoardInner) << index; // set bit (if needed)
}
#[cfg(feature = "bitvec")]
pub fn get_by_index(&self, index: CoordAxis) -> bool {
pub fn get_by_index(&self, index: CoordPairInner) -> bool {
self.0[index as usize]
}
#[cfg(feature = "bitvec")]
pub fn set_by_index(&mut self, index: CoordAxis, value: bool) {
pub fn set_by_index(&mut self, index: CoordPairInner, value: bool) {
self.0.set(index as usize, value);
}