sit-algos 0.3.0

Implementation of decompression algorithms used by StuffIt Expander and related applications
Documentation
pub struct Window<const N: usize> {
    data: [u8; N],
    pos: usize,
}

impl<const N: usize> Window<N> {
    const MASK: usize = N - 1;

    #[inline]
    pub fn new() -> Self {
        Self {
            data: [0u8; _],
            pos: 0,
        }
    }

    #[inline]
    pub fn put(&mut self, v: u8) -> u8 {
        self.data[self.pos] = v;
        self.pos = (self.pos + 1) & Self::MASK;
        v
    }

    #[inline]
    pub fn get(&mut self, offset: u32) -> u8 {
        let pos = (self.pos as u32).wrapping_add(N as u32 - offset) & Self::MASK as u32;
        self.data[pos as usize]
    }
}