fix implementation

This commit is contained in:
Corwin Kuiper 2021-06-04 19:15:58 +01:00
parent a17b37c2b7
commit 3cdb966dd9

View file

@ -9,7 +9,7 @@ impl<const N: usize> Bitarray<N> {
pub fn get(&self, index: usize) -> Option<bool> {
if index < N * 32 {
Some((self.a[index / 32] >> (N % 32) & 1) != 0)
Some((self.a[index / 32] >> (index % 32) & 1) != 0)
} else {
None
}
@ -17,8 +17,8 @@ impl<const N: usize> Bitarray<N> {
pub fn set(&mut self, index: usize, value: bool) {
let value = value as u32;
let mask = 1 << (N % 32);
let value_mask = value << (N % 32);
let mask = 1 << (index % 32);
let value_mask = value << (index % 32);
self.a[index / 32] = self.a[index / 32] & !mask | value_mask
}
}