| 1 |
use alloc::boxed::Box; |
| 2 |
|
| 3 |
/// Number of distinct literal/length symbols in DEFLATE |
| 4 |
pub const ZOPFLI_NUM_LL: usize = 288; |
| 5 |
/// Number of distinct distance symbols in DEFLATE |
| 6 |
pub const ZOPFLI_NUM_D: usize = 32; |
| 7 |
|
| 8 |
/// The window size for deflate. Must be a power of two. This should be 32768, the |
| 9 |
/// maximum possible by the deflate spec. Anything less hurts compression more than |
| 10 |
/// speed. |
| 11 |
pub const ZOPFLI_WINDOW_SIZE: usize = 32768; |
| 12 |
/// A block structure of huge, non-smart, blocks to divide the input into, to allow |
| 13 |
/// operating on huge files without exceeding memory, such as the 1GB wiki9 corpus. |
| 14 |
/// The whole compression algorithm, including the smarter block splitting, will |
| 15 |
/// be executed independently on each huge block. |
| 16 |
/// Dividing into huge blocks hurts compression, but not much relative to the size. |
| 17 |
/// This must be equal or greater than `ZOPFLI_WINDOW_SIZE`. |
| 18 |
#[cfg(feature = "std")] |
| 19 |
pub const ZOPFLI_MASTER_BLOCK_SIZE: usize = 1_000_000; |
| 20 |
|
| 21 |
/// The window mask used to wrap indices into the window. This is why the |
| 22 |
/// window size must be a power of two. |
| 23 |
pub const ZOPFLI_WINDOW_MASK: usize = ZOPFLI_WINDOW_SIZE - 1; |
| 24 |
|
| 25 |
/// Maximum length that can be encoded in deflate. |
| 26 |
pub const ZOPFLI_MAX_MATCH: usize = 258; |
| 27 |
/// Minimum length that can be encoded in deflate. |
| 28 |
pub const ZOPFLI_MIN_MATCH: usize = 3; |
| 29 |
|
| 30 |
/// For longest match cache. max 256. Uses huge amounts of memory but makes it |
| 31 |
/// faster. Uses this many times three bytes per single byte of the input data. |
| 32 |
/// This is so because longest match finding has to find the exact distance |
| 33 |
/// that belongs to each length for the best lz77 strategy. |
| 34 |
/// Good values: e.g. 5, 8. |
| 35 |
pub const ZOPFLI_CACHE_LENGTH: usize = 8; |
| 36 |
|
| 37 |
/// limit the max hash chain hits for this hash value. This has an effect only |
| 38 |
/// on files where the hash value is the same very often. On these files, this |
| 39 |
/// gives worse compression (the value should ideally be 32768, which is the |
| 40 |
/// `ZOPFLI_WINDOW_SIZE`, while zlib uses 4096 even for best level), but makes it |
| 41 |
/// faster on some specific files. |
| 42 |
/// Good value: e.g. 8192. |
| 43 |
pub const ZOPFLI_MAX_CHAIN_HITS: usize = 8192; |
| 44 |
|
| 45 |
#[inline] |
| 46 |
pub fn boxed_array<T: Clone, const N: usize>(element: T) -> Box<[T; N]> { |
| 47 |
match vec![element; N].into_boxed_slice().try_into() { |
| 48 |
Ok(x) => x, |
| 49 |
Err(_) => unreachable!(), |
| 50 |
} |
| 51 |
} |