pub const MIN_MATCH: usize = 4;
pub const MIN_RUN: usize = 8;
pub const DEFAULT_WINSIZE: usize = 1 << 23;
pub const DEFAULT_SPREVSZ: usize = 1 << 18;
pub const DEFAULT_SRCWINSZ: usize = 1 << 26;
pub const MAX_LRU_SIZE: usize = 32;
#[derive(Debug, Clone, Copy)]
pub struct MatcherConfig {
pub name: &'static str,
pub large_look: usize,
pub large_step: usize,
pub small_look: usize,
pub small_chain: usize,
pub small_lchain: usize,
pub max_lazy: usize,
pub long_enough: usize,
}
pub fn config_for_level(level: u32) -> MatcherConfig {
match level {
0 | 1 => FASTEST,
2 => FASTER,
3..=5 => FAST,
6 => DEFAULT,
_ => SLOW,
}
}
pub const FASTEST: MatcherConfig = MatcherConfig {
name: "fastest",
large_look: 9,
large_step: 26,
small_look: 4,
small_chain: 1,
small_lchain: 1,
max_lazy: 6,
long_enough: 6,
};
pub const FASTER: MatcherConfig = MatcherConfig {
name: "faster",
large_look: 9,
large_step: 15,
small_look: 4,
small_chain: 1,
small_lchain: 1,
max_lazy: 18,
long_enough: 18,
};
pub const FAST: MatcherConfig = MatcherConfig {
name: "fast",
large_look: 9,
large_step: 8,
small_look: 4,
small_chain: 4,
small_lchain: 1,
max_lazy: 18,
long_enough: 35,
};
pub const DEFAULT: MatcherConfig = MatcherConfig {
name: "default",
large_look: 9,
large_step: 3,
small_look: 4,
small_chain: 8,
small_lchain: 2,
max_lazy: 36,
long_enough: 70,
};
pub const SLOW: MatcherConfig = MatcherConfig {
name: "slow",
large_look: 9,
large_step: 2,
small_look: 4,
small_chain: 44,
small_lchain: 13,
max_lazy: 90,
long_enough: 70,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn all_profiles_have_slook_4() {
for p in [FASTEST, FASTER, FAST, DEFAULT, SLOW] {
assert_eq!(
p.small_look, MIN_MATCH,
"profile {} has wrong small_look",
p.name
);
}
}
#[test]
fn all_profiles_have_llook_9() {
for p in [FASTEST, FASTER, FAST, DEFAULT, SLOW] {
assert_eq!(p.large_look, 9, "profile {} has wrong large_look", p.name);
}
}
#[test]
fn level_mapping() {
assert_eq!(config_for_level(0).name, "fastest");
assert_eq!(config_for_level(1).name, "fastest");
assert_eq!(config_for_level(2).name, "faster");
assert_eq!(config_for_level(3).name, "fast");
assert_eq!(config_for_level(5).name, "fast");
assert_eq!(config_for_level(6).name, "default");
assert_eq!(config_for_level(7).name, "slow");
assert_eq!(config_for_level(9).name, "slow");
}
}