Struct lzss::Lzss [−][src]
Expand description
A zero-sized type, the const generics specify the parameters of the compression.
Parameters
EI
- The number of bits in the offset, usualy10..13
EJ
- The number of bits in the length, usually4..5
C
- The initial fill byte of the buffer, usually0x20
(space)N
- Equals1 << EI
, the size of the buffer for Lzss::decompress()N2
- Equals2 << EI
(N * 2
), the size of the buffer for Lzss::compress()
Restrictions
EJ
must be larger than0
EI
must be larger thanEJ
EI + EJ
must be at least 8EI + EJ
must be 24 or lessN
must be equal to1 << EI
N2
must be equal to2 << EI
(N * 2
)
Limitations
Since it’s not possible to do const calculations on const generics all parameters have to be set.
With feature const_panic
All parameters are checked at compile-time.
There is no runtime overhead since everything is checked during compile-time.
Without feature const_panic
All parameters are checked at runtime.
There should be no runtime overhead since the compiler will replace the funtion with a panic if there is a problem. You just won’t notice that during compilation.
Example
type MyLzss = Lzss<10, 4, 0x20, { 1 << 10 }, { 2 << 10 }>; let input = b"Example Data"; let mut output = [0; 14]; let result = MyLzss::compress( SliceReader::new(input), SliceWriterExact::new(&mut output), ); assert!(result.is_ok()); // the output is exactly 14 bytes long
Implementations
Compress the input data into the output.
The buffer, with N2
bytes, is allocated on the stack.
alloc/std
Compress the input data into the output.
The buffer, with N2
bytes, is allocated on the heap.
Compress the input data into the output.
Decompress the input data into the output.
The buffer, with N
bytes, is allocated on the stack.
alloc/std
Decompress the input data into the output.
The buffer, with N
bytes, is allocated on the heap.
Compress, the input and output is in the same slice.
The input is located at io[offset..]
.
When there is enough space in the slice then the result will be (size, None)
.
And the output is located at io[0..size]
.
If there is not enough space in the slice, i.e. the output (or buffer) would overwrite
the input, then the result will be (size, Some(new_offset))
, the already compressed
data is in io[0..size]
and the not yet compressed data is in io[new_offset..]
.
Even when the compression fails due to space the data is recoverable.
The minimum offset is Lzss::MIN_OFFSET, though if the offset is Lzss::MIN_OFFSET + input_size/8
then the compression can’t fail.
The minimal offset when using compress_in_place
.
It’s a little less than N
.
Auto Trait Implementations
impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> RefUnwindSafe for Lzss<EI, EJ, C, N, N2>
impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> Send for Lzss<EI, EJ, C, N, N2>
impl<const EI: usize, const EJ: usize, const C: u8, const N: usize, const N2: usize> Sync for Lzss<EI, EJ, C, N, N2>