miniz_oxide/deflate/
buffer.rs1use crate::deflate::core::{LZ_DICT_SIZE, MAX_MATCH_LEN};
6use alloc::boxed::Box;
7use alloc::vec;
8
9pub const LZ_CODE_BUF_SIZE: usize = 64 * 1024;
11pub const LZ_CODE_BUF_MASK: usize = LZ_CODE_BUF_SIZE - 1;
12pub const OUT_BUF_SIZE: usize = (LZ_CODE_BUF_SIZE * 13) / 10;
14pub const LZ_DICT_FULL_SIZE: usize = LZ_DICT_SIZE + MAX_MATCH_LEN - 1 + 1;
15
16pub const LZ_HASH_BITS: i32 = 15;
18pub const LZ_HASH_SHIFT: i32 = (LZ_HASH_BITS + 2) / 3;
20pub const LZ_HASH_SIZE: usize = 1 << LZ_HASH_BITS;
22
23#[inline]
24pub const fn update_hash(current_hash: u16, byte: u8) -> u16 {
25 ((current_hash << LZ_HASH_SHIFT) ^ byte as u16) & (LZ_HASH_SIZE as u16 - 1)
26}
27
28#[derive(Clone)]
29pub struct HashBuffers {
30 pub dict: Box<[u8; LZ_DICT_FULL_SIZE]>,
31 pub next: Box<[u16; LZ_DICT_SIZE]>,
32 pub hash: Box<[u16; LZ_DICT_SIZE]>,
33}
34
35impl HashBuffers {
36 #[inline]
37 pub fn reset(&mut self) {
38 self.dict.fill(0);
39 self.next.fill(0);
40 self.hash.fill(0);
41 }
42}
43
44impl Default for HashBuffers {
45 fn default() -> HashBuffers {
46 HashBuffers {
47 dict: vec![0; LZ_DICT_FULL_SIZE]
48 .into_boxed_slice()
49 .try_into()
50 .unwrap(),
51 next: vec![0; LZ_DICT_SIZE].into_boxed_slice().try_into().unwrap(),
52 hash: vec![0; LZ_DICT_SIZE].into_boxed_slice().try_into().unwrap(),
53 }
54 }
55}
56
57#[derive(Clone)]
58pub struct LocalBuf {
59 pub b: [u8; OUT_BUF_SIZE],
60}
61
62impl Default for LocalBuf {
63 fn default() -> LocalBuf {
64 LocalBuf {
65 b: [0; OUT_BUF_SIZE],
66 }
67 }
68}