1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
use storage::BlockType; use traits::*; macro_rules! impl_bits_prim { ( $t:ident ) => { impl BitVec for $t { type Block = $t; #[inline] fn bit_len(&self) -> u64 { Self::nbits() as u64 } #[inline] fn bit_offset(&self) -> u8 { 0 } #[inline] fn block_len(&self) -> usize { 1 } #[inline] fn get_bit(&self, position: u64) -> bool { assert!(position < self.bit_len(), "prim::get_bit: out of bounds"); BlockType::get_bit(*self, position as usize) } #[inline] fn get_block(&self, position: usize) -> Self::Block { assert!(position == 0, "prim::get_block: out of bounds"); *self } #[inline] fn get_bits(&self, start: u64, count: usize) -> Self { assert!(start + count as u64 <= Self::nbits() as u64, "prim::get_bits: out of bounds"); BlockType::get_bits(*self, start as usize, count) } } impl BitVecMut for $t { #[inline] fn set_bit(&mut self, position: u64, value: bool) { assert!(position < self.bit_len(), "prim::set_bit: out of bounds"); *self = self.with_bit(position as usize, value); } #[inline] fn set_block(&mut self, position: usize, value: Self::Block) { assert!(position == 0, "prim::set_block: out of bounds"); *self = value; } #[inline] fn set_bits(&mut self, start: u64, count: usize, value: Self::Block) { assert!(start + count as u64 <= Self::nbits() as u64, "prim::set_bits: out of bounds"); *self = self.with_bits(start as usize, count, value); } } } } impl_bits_prim!(u8); impl_bits_prim!(u16); impl_bits_prim!(u32); impl_bits_prim!(u64); impl_bits_prim!(usize);