Simple complete conflict avoidance.

This commit is contained in:
hal8174 2024-01-16 02:31:20 +01:00
parent 993fb0730c
commit 2e9c699600
3 changed files with 83 additions and 18 deletions

View file

@ -27,15 +27,35 @@ where
}
pub fn get(&self, x: usize, y: usize) -> &T {
assert!(x < self.width);
assert!(y < self.height);
assert!(
x < self.width,
"assertion failed: x < self.width; x: {}, self.width: {}",
x,
self.width
);
assert!(
y < self.height,
"assertion failed: y < self.height; y: {}, self.height: {}",
y,
self.height
);
let i = self.index(x, y);
self.data.get(i).unwrap()
}
pub fn get_mut(&mut self, x: usize, y: usize) -> &mut T {
assert!(x < self.width);
assert!(y < self.height);
assert!(
x < self.width,
"assertion failed: x < self.width; x: {}, self.width: {}",
x,
self.width
);
assert!(
y < self.height,
"assertion failed: y < self.height; y: {}, self.height: {}",
y,
self.height
);
let i = self.index(x, y);
self.data.get_mut(i).unwrap()
}