diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2018-10-23 19:05:02 +0200 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2018-10-23 19:05:02 +0200 |
commit | 6465a94691189acfc2fc2909e6e24442a1f0b700 (patch) | |
tree | d0127af70517832e84d489dd5aa5b0ba72a2493a | |
parent | 843c8c87a1d0df3a3522f34c9c256be72c7c1f18 (diff) | |
download | nihav-6465a94691189acfc2fc2909e6e24442a1f0b700.tar.gz |
io: generic table codebook description reader
-rw-r--r-- | src/io/codebook.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/io/codebook.rs b/src/io/codebook.rs index d67e790..5bfd719 100644 --- a/src/io/codebook.rs +++ b/src/io/codebook.rs @@ -309,6 +309,25 @@ impl CodebookDescReader<u32> for ShortCodebookDescReader { fn len(&mut self) -> usize { self.data.len() } } +pub struct TableCodebookDescReader<CodeType:'static, IndexType:'static> { + bits: &'static [u8], + codes: &'static [CodeType], + idx_map: fn(usize) -> IndexType, +} + +impl<'a, CodeType, IndexType> TableCodebookDescReader<CodeType, IndexType> { + pub fn new(codes: &'static [CodeType], bits: &'static [u8], idx_map: fn(usize) -> IndexType) -> Self { + Self { bits, codes, idx_map } + } +} +impl<CodeType: Copy+Into<u32>, IndexType> CodebookDescReader<IndexType> for TableCodebookDescReader<CodeType, IndexType> +{ + fn bits(&mut self, idx: usize) -> u8 { self.bits[idx] } + fn code(&mut self, idx: usize) -> u32 { self.codes[idx].into() } + fn sym (&mut self, idx: usize) -> IndexType { (self.idx_map)(idx) } + fn len(&mut self) -> usize { self.bits.len() } +} + #[cfg(test)] mod test { use super::*; |