mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
fix implementation
This commit is contained in:
parent
a17b37c2b7
commit
3cdb966dd9
|
@ -9,7 +9,7 @@ impl<const N: usize> Bitarray<N> {
|
||||||
|
|
||||||
pub fn get(&self, index: usize) -> Option<bool> {
|
pub fn get(&self, index: usize) -> Option<bool> {
|
||||||
if index < N * 32 {
|
if index < N * 32 {
|
||||||
Some((self.a[index / 32] >> (N % 32) & 1) != 0)
|
Some((self.a[index / 32] >> (index % 32) & 1) != 0)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ impl<const N: usize> Bitarray<N> {
|
||||||
|
|
||||||
pub fn set(&mut self, index: usize, value: bool) {
|
pub fn set(&mut self, index: usize, value: bool) {
|
||||||
let value = value as u32;
|
let value = value as u32;
|
||||||
let mask = 1 << (N % 32);
|
let mask = 1 << (index % 32);
|
||||||
let value_mask = value << (N % 32);
|
let value_mask = value << (index % 32);
|
||||||
self.a[index / 32] = self.a[index / 32] & !mask | value_mask
|
self.a[index / 32] = self.a[index / 32] & !mask | value_mask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue