Skip to content

Instantly share code, notes, and snippets.

@thomwiggers
Created March 29, 2018 13:28
Show Gist options
  • Save thomwiggers/11ee947373c54faf14608070a6bc2837 to your computer and use it in GitHub Desktop.
Save thomwiggers/11ee947373c54faf14608070a6bc2837 to your computer and use it in GitHub Desktop.
macro_rules! implement_index {
($t: ty, $size: expr) => {
impl ops::Index<usize> for BitVector<$t> {
type Output = u8;
fn index(&self, index: usize) -> Self::Output {
let block_index = index / $size;
let remainder = index % $size;
(self.0[block_index] >> remainder) & 1
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment