mod decoder;
mod encoder;
mod table;
mod tans_encoder;
use std::sync::OnceLock;
pub use decoder::{BitReader, FseDecoder};
pub use encoder::{FseBitWriter, FseEncoder, InterleavedFseEncoder};
pub use table::{
FseTable, FseTableEntry, FSE_MAX_ACCURACY_LOG, LITERAL_LENGTH_DEFAULT_DISTRIBUTION,
MATCH_LENGTH_DEFAULT_DISTRIBUTION, OFFSET_DEFAULT_DISTRIBUTION,
};
pub use tans_encoder::{InterleavedTansEncoder, TansEncoder, TansSymbolParams};
static CACHED_LL_TABLE: OnceLock<FseTable> = OnceLock::new();
static CACHED_OF_TABLE: OnceLock<FseTable> = OnceLock::new();
static CACHED_ML_TABLE: OnceLock<FseTable> = OnceLock::new();
#[inline]
pub fn cached_ll_table() -> &'static FseTable {
CACHED_LL_TABLE.get_or_init(|| {
FseTable::from_hardcoded_ll().expect("LL predefined table construction should never fail")
})
}
#[inline]
pub fn cached_of_table() -> &'static FseTable {
CACHED_OF_TABLE.get_or_init(|| {
FseTable::from_hardcoded_of().expect("OF predefined table construction should never fail")
})
}
#[inline]
pub fn cached_ml_table() -> &'static FseTable {
CACHED_ML_TABLE.get_or_init(|| {
FseTable::from_hardcoded_ml().expect("ML predefined table construction should never fail")
})
}
static CACHED_LL_ENCODER: OnceLock<TansEncoder> = OnceLock::new();
static CACHED_OF_ENCODER: OnceLock<TansEncoder> = OnceLock::new();
static CACHED_ML_ENCODER: OnceLock<TansEncoder> = OnceLock::new();
#[inline]
pub fn cloned_ll_encoder() -> TansEncoder {
CACHED_LL_ENCODER
.get_or_init(|| TansEncoder::from_decode_table(cached_ll_table()))
.clone()
}
#[inline]
pub fn cloned_of_encoder() -> TansEncoder {
CACHED_OF_ENCODER
.get_or_init(|| TansEncoder::from_decode_table(cached_of_table()))
.clone()
}
#[inline]
pub fn cloned_ml_encoder() -> TansEncoder {
CACHED_ML_ENCODER
.get_or_init(|| TansEncoder::from_decode_table(cached_ml_table()))
.clone()
}
pub const LITERAL_LENGTH_ACCURACY_LOG: u8 = 6;
pub const MATCH_LENGTH_ACCURACY_LOG: u8 = 6;
pub const OFFSET_ACCURACY_LOG: u8 = 5;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_constants() {
assert!(FSE_MAX_ACCURACY_LOG <= 15);
assert!(LITERAL_LENGTH_ACCURACY_LOG <= FSE_MAX_ACCURACY_LOG);
assert!(MATCH_LENGTH_ACCURACY_LOG <= FSE_MAX_ACCURACY_LOG);
assert!(OFFSET_ACCURACY_LOG <= FSE_MAX_ACCURACY_LOG);
}
}