initial BVM usage (halfs performance :( )
This commit is contained in:
@@ -26,11 +26,21 @@ type ChainCollection = ArrayVec<Chain, 8>;
|
||||
/// Map of all points on the board against some type T
|
||||
/// Used to index like so: example[i][j]
|
||||
/// with each coordinate
|
||||
pub struct PosMap<T>(ArrayVec<T, BOARD_AREA>);
|
||||
pub struct PosMap<T: Default>(ArrayVec<T, BOARD_AREA>);
|
||||
|
||||
impl<T: Default> PosMap<T> {
|
||||
const fn index(row: usize, col: usize) -> usize {
|
||||
row * BOARD_SIZE + col
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self(ArrayVec::from_iter(
|
||||
(0..BOARD_AREA).map(|_| Default::default()),
|
||||
))
|
||||
}
|
||||
|
||||
impl<T> PosMap<T> {
|
||||
pub fn get(&self, row: usize, col: usize) -> &T {
|
||||
let index = row * BOARD_SIZE + col;
|
||||
let index = Self::index(row, col);
|
||||
|
||||
debug_assert!(
|
||||
BOARD_AREA + 1 >= index,
|
||||
@@ -40,6 +50,17 @@ impl<T> PosMap<T> {
|
||||
|
||||
unsafe { self.0.get_unchecked(index) }
|
||||
}
|
||||
|
||||
pub fn set(&mut self, row: usize, col: usize, value: T) {
|
||||
let index = Self::index(row, col);
|
||||
debug_assert!(
|
||||
BOARD_AREA + 1 >= index,
|
||||
"index out of range, was: {}",
|
||||
index
|
||||
);
|
||||
|
||||
self.0[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a lookup map for adjacencies and chains from each position on the board
|
||||
|
||||
Reference in New Issue
Block a user