brotli/enc/
block_split.rs
1use super::super::alloc;
2use super::super::alloc::{Allocator, SliceWrapper};
3use crate::enc::combined_alloc::alloc_default;
4
5pub struct BlockSplit<Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>> {
6 pub num_types: usize,
7 pub num_blocks: usize,
8 pub types: <Alloc as Allocator<u8>>::AllocatedMemory,
9 pub lengths: <Alloc as Allocator<u32>>::AllocatedMemory,
10}
11
12impl<Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>> Default for BlockSplit<Alloc> {
13 fn default() -> Self {
14 Self {
15 num_types: 0,
16 num_blocks: 0,
17 types: alloc_default::<u8, Alloc>(),
18 lengths: alloc_default::<u32, Alloc>(),
19 }
20 }
21}
22
23impl<Alloc: alloc::Allocator<u8> + alloc::Allocator<u32>> BlockSplit<Alloc> {
24 pub fn new() -> BlockSplit<Alloc> {
25 Self::default()
26 }
27 pub fn destroy(&mut self, m: &mut Alloc) {
28 <Alloc as Allocator<u8>>::free_cell(m, core::mem::take(&mut self.types));
29 <Alloc as Allocator<u32>>::free_cell(m, core::mem::take(&mut self.lengths));
30 self.num_blocks = 0;
31 self.num_types = 0;
32 }
33 pub fn types_alloc_size(&self) -> usize {
34 self.types.slice().len()
35 }
36 pub fn lengths_alloc_size(&self) -> usize {
37 self.lengths.slice().len()
38 }
39}