use proper type for bitboard indexing
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
board::Board,
|
board::Board,
|
||||||
coords::{CoordAxis, CoordPair},
|
coords::{CoordPair, CoordPairInner},
|
||||||
};
|
};
|
||||||
use const_fn::const_fn;
|
use const_fn::const_fn;
|
||||||
use static_assertions::const_assert;
|
use static_assertions::const_assert;
|
||||||
@@ -53,24 +53,24 @@ impl BitBoard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "bitvec"))]
|
#[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
|
((self.0 >> index) & 0b1) != 0b0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "bitvec"))]
|
#[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)
|
// PERF! branchless setting of bit (~+3% perf bump)
|
||||||
self.0 &= !(0b1 << index); // clear bit
|
self.0 &= !(0b1 << index); // clear bit
|
||||||
self.0 |= (value as BitBoardInner) << index; // set bit (if needed)
|
self.0 |= (value as BitBoardInner) << index; // set bit (if needed)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bitvec")]
|
#[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]
|
self.0[index as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "bitvec")]
|
#[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);
|
self.0.set(index as usize, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user