pub struct UltraFastEntropyCalculator { /* private fields */ }Implementations§
Source§impl UltraFastEntropyCalculator
impl UltraFastEntropyCalculator
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/basic_usage.rs (line 49)
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}Sourcepub fn build_from_corpus<I>(&mut self, corpus_chunks: I) -> Result<()>
pub fn build_from_corpus<I>(&mut self, corpus_chunks: I) -> Result<()>
Examples found in repository?
examples/basic_usage.rs (line 53)
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}pub fn calculate_entropy_fast( &mut self, bytes: &[u8], pos: usize, ) -> Result<f32>
pub fn calculate_context_entropy( &mut self, bytes: &[u8], pos: usize, context_size: usize, ) -> Result<f32>
pub fn calculate_adaptive_entropy( &mut self, bytes: &[u8], pos: usize, ) -> Result<f32>
pub fn get_entropy_statistics(&self) -> EntropyStatistics
pub fn predict_next_byte_entropy( &mut self, bytes: &[u8], pos: usize, ) -> Result<f32>
Auto Trait Implementations§
impl Freeze for UltraFastEntropyCalculator
impl RefUnwindSafe for UltraFastEntropyCalculator
impl Send for UltraFastEntropyCalculator
impl Sync for UltraFastEntropyCalculator
impl Unpin for UltraFastEntropyCalculator
impl UnwindSafe for UltraFastEntropyCalculator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more