atlas-archive-core 1.1.0

High-performance compression library with adaptive context modeling (Loom) and .nyx archives
Documentation
use atlas_archive_core::{Compressor, LoomCompressor, LoomMode, PlcConfig};

#[test]
fn test_regression_paged_vs_standard() {
    // 1. Generate repetitive data (Structured)
    let mut data = Vec::new();
    for i in 0..5000 {
        // Pattern: [0..10] + [Index] + [Random noise]
        // This favors Transformer (Standard) which learns the index sequence
        // Paged (PPM) might struggle if context is too shallow or weighting is off.
        data.extend_from_slice(b"ABCDEFGHIJ");
        data.extend_from_slice(&(i as u32).to_be_bytes());
        // Small noise
        data.push((i % 255) as u8);
    }
    // Total len: 5000 * (10 + 4 + 1) = 75,000 bytes

    println!("Data Size: {}", data.len());

    // 2. Standard Loom (Transformer) - Expected Ratio ~0.002
    let mut std_conf = PlcConfig::default();
    std_conf.loom_mode = LoomMode::Standard;
    std_conf.max_nodes = 1_000_000; // Unbounded RAM
    let mut std_comp = LoomCompressor::new(std_conf);
    let start_std = std::time::Instant::now();
    let res_std = std_comp.compress(&data).unwrap();
    let ratio_std = res_std.len() as f64 / data.len() as f64;
    println!(
        "Standard (Transformer): Ratio {:.6} (Size {}), Time {:?}",
        ratio_std,
        res_std.len(),
        start_std.elapsed()
    );

    // 3. Paged Loom (Adaptive) - Expected 0.024 (Regression) vs 0.0057 (Fixed?)
    let mut paged_conf = PlcConfig::ultra(); // Uses Paged
    paged_conf.verbose = true;
    let mut paged_comp = LoomCompressor::new(paged_conf);
    let start_paged = std::time::Instant::now();
    let res_paged = paged_comp.compress(&data).unwrap();
    let ratio_paged = res_paged.len() as f64 / data.len() as f64;
    println!(
        "Paged (Ultra):          Ratio {:.6} (Size {}), Time {:?}",
        ratio_paged,
        res_paged.len(),
        start_paged.elapsed()
    );

    // 4. Analysis
    println!("Gap: {:.2}x", ratio_paged / ratio_std);

    // Fail if gap is huge (> 10x)
    // Transformer (0.002) vs Paged (0.02) is 10x.
    // If Paged hits 0.006, gap is 3x (Acceptable tradeoff for OOM safety).
}