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