bitboard: use Coord type
This commit is contained in:
parent
a68e2e093b
commit
992ca01169
@ -44,34 +44,34 @@ impl BitBoard {
|
||||
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
pub const fn get(&self, row: Coord, col: Coord) -> bool {
|
||||
self.get_by_index(get_index(row, col) as usize)
|
||||
self.get_by_index(get_index(row, col))
|
||||
}
|
||||
|
||||
#[const_fn(cfg(not(feature = "bitvec")))]
|
||||
pub const fn set(&mut self, row: Coord, col: Coord, value: bool) {
|
||||
self.set_by_index(get_index(row, col) as usize, value);
|
||||
self.set_by_index(get_index(row, col), value);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bitvec"))]
|
||||
const fn get_by_index(&self, index: usize) -> bool {
|
||||
const fn get_by_index(&self, index: Coord) -> bool {
|
||||
((self.0 >> index) & 0b1) != 0b0
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bitvec"))]
|
||||
const fn set_by_index(&mut self, index: usize, value: bool) {
|
||||
const fn set_by_index(&mut self, index: Coord, 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: usize) -> bool {
|
||||
self.0[index]
|
||||
pub fn get_by_index(&self, index: Coord) -> bool {
|
||||
self.0[index as usize]
|
||||
}
|
||||
|
||||
#[cfg(feature = "bitvec")]
|
||||
pub fn set_by_index(&mut self, index: usize, value: bool) {
|
||||
self.0.set(index, value);
|
||||
pub fn set_by_index(&mut self, index: Coord, value: bool) {
|
||||
self.0.set(index as usize, value);
|
||||
}
|
||||
|
||||
// works on both `bitvec` and native (const on native)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user