diff options
Diffstat (limited to 'src/common/mod.rs')
-rw-r--r-- | src/common/mod.rs | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/src/common/mod.rs b/src/common/mod.rs index 0c64d5f..50549cc 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,12 +1,17 @@ mod serialize; mod timer; mod vint; +mod bitpacker; + pub use self::serialize::BinarySerializable; pub use self::timer::Timing; pub use self::timer::TimerTree; pub use self::timer::OpenTimer; pub use self::vint::VInt; +pub use self::bitpacker::compute_num_bits; + + use std::io; pub fn make_io_err(msg: String) -> io::Error { @@ -26,36 +31,3 @@ pub trait HasLen { } -fn count_leading_zeros(mut val: u32) -> u8 { - if val == 0 { - return 32; - } - let mut result = 0u8; - while (val & (1u32 << 31)) == 0 { - val <<= 1; - result += 1; - } - result -} - - -pub fn compute_num_bits(amplitude: u32) -> u8 { - 32u8 - count_leading_zeros(amplitude) -} - - - -#[cfg(test)] -mod test { - use super::compute_num_bits; - - fn test_compute_num_bits() { - assert_eq!(compute_num_bits(1), 1u8); - assert_eq!(compute_num_bits(0), 0u8); - assert_eq!(compute_num_bits(2), 2u8); - assert_eq!(compute_num_bits(3), 2u8); - assert_eq!(compute_num_bits(4), 3u8); - assert_eq!(compute_num_bits(255), 8u8); - assert_eq!(compute_num_bits(256), 9u8); - } -}
\ No newline at end of file |