basic_usage/
basic_usage.rs

1use byteforge::*;
2use byteforge::patching::MultiSignalPatcher;
3use byteforge::entropy::UltraFastEntropyCalculator;
4use std::time::Instant;
5
6
7fn main() -> Result<()> {
8    println!("🚀 ByteForge Basic Usage Example");
9    println!("=================================");
10
11    
12    let config = ByteForgeConfig {
13        patch_size_range: (2, 12),
14        entropy_threshold: 0.6,
15        compression_threshold: 0.4,
16        semantic_weight: 0.3,
17        model_dim: 256,
18        num_heads: 8,
19        num_layers: 4,
20        vocab_size: 256,
21        max_seq_len: 2048,
22        use_quantization: true,
23        use_streaming: false,
24    };
25
26    
27    let repetitive_text = "abc123".repeat(10);
28    let examples = vec![
29        ("Simple Text", "Hello, world! This is a simple example."),
30        ("Code Sample", r#"
31fn fibonacci(n: u32) -> u32 {
32    match n {
33        0 => 0,
34        1 => 1,
35        _ => fibonacci(n - 1) + fibonacci(n - 2),
36    }
37}
38"#),
39        ("JSON Data", r#"{"name": "ByteForge", "fast": true, "version": "0.1.0"}"#),
40        ("Repetitive", &repetitive_text),
41    ];
42
43    for (name, text) in examples {
44        println!("\n Processing: {}", name);
45        println!("Input: {}", text);
46        
47        
48        let mut patcher = MultiSignalPatcher::new(config.clone());
49        let mut entropy_calc = UltraFastEntropyCalculator::new();
50        
51        
52        let corpus = vec![text.as_bytes().to_vec()];
53        entropy_calc.build_from_corpus(corpus)?;
54        
55        
56        let start = Instant::now();
57        let patches = patcher.patch_bytes(text.as_bytes())?;
58        let duration = start.elapsed();
59        
60        println!(" Created {} patches in {:?}", patches.len(), duration);
61        
62        for (i, patch) in patches.iter().enumerate() {
63            let patch_str = String::from_utf8_lossy(&patch.bytes);
64            println!("  Patch {}: '{}' (type: {:?}, complexity: {:.2})", 
65                     i + 1, patch_str, patch.patch_type, patch.complexity_score);
66        }
67        
68        
69        let fixed_patches = (text.len() as f32 / 4.0).ceil() as usize;
70        let efficiency = fixed_patches as f32 / patches.len() as f32;
71        println!("âš¡ Efficiency vs 4-byte patches: {:.1}x", efficiency);
72    }
73
74    println!("\n Example completed successfully!");
75    Ok(())
76}