MultiSignalPatcher

Struct MultiSignalPatcher 

Source
pub struct MultiSignalPatcher { /* private fields */ }

Implementations§

Source§

impl MultiSignalPatcher

Source

pub fn new(config: ByteForgeConfig) -> Self

Examples found in repository?
examples/basic_usage.rs (line 48)
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}
Source

pub fn patch_bytes(&mut self, bytes: &[u8]) -> Result<Vec<Patch>>

Examples found in repository?
examples/basic_usage.rs (line 57)
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}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.