pub struct ReversibleVSAEncoder { /* private fields */ }Expand description
Reversible encoder using position-aware VSA binding
Implementations§
Source§impl ReversibleVSAEncoder
impl ReversibleVSAEncoder
Sourcepub fn encode(&mut self, data: &[u8]) -> SparseVec
pub fn encode(&mut self, data: &[u8]) -> SparseVec
Encode data into a holographic representation
Returns a single SparseVec that contains all the data holographically.
Sourcepub fn encode_chunked(
&mut self,
data: &[u8],
chunk_size: usize,
) -> Vec<SparseVec>
pub fn encode_chunked( &mut self, data: &[u8], chunk_size: usize, ) -> Vec<SparseVec>
Encode data in chunks for better accuracy with large files
Returns a vector of SparseVecs, one per chunk.
§Panics
Panics if chunk_size is 0.
Sourcepub fn decode(&self, encoded: &SparseVec, length: usize) -> Vec<u8> ⓘ
pub fn decode(&self, encoded: &SparseVec, length: usize) -> Vec<u8> ⓘ
Decode data from a holographic representation
Uses bind + similarity search to retrieve each byte.
Sourcepub fn decode_chunked(
&self,
chunks: &[SparseVec],
chunk_size: usize,
total_length: usize,
) -> Vec<u8> ⓘ
pub fn decode_chunked( &self, chunks: &[SparseVec], chunk_size: usize, total_length: usize, ) -> Vec<u8> ⓘ
Sourcepub fn get_byte_vectors(&self) -> &[SparseVec]
pub fn get_byte_vectors(&self) -> &[SparseVec]
Get reference to byte vectors (for GPU acceleration)
Returns slice of 256 basis vectors, one per byte value.
Sourcepub fn get_position_vector_ref(&self, pos: usize) -> &SparseVec
pub fn get_position_vector_ref(&self, pos: usize) -> &SparseVec
Get position vector for a given position (for GPU acceleration)
Returns reference to position basis vector. Uses modulo if position exceeds pre-allocated vectors.
Note: Call ensure_positions(max_pos) first if you need exact position
vectors without modulo wrapping.
Sourcepub fn ensure_positions(&mut self, max_pos: usize)
pub fn ensure_positions(&mut self, max_pos: usize)
Sourcepub fn try_ensure_positions(&mut self, max_pos: usize) -> Result<(), String>
pub fn try_ensure_positions(&mut self, max_pos: usize) -> Result<(), String>
Ensure position vectors exist up to the given position, returning error on invalid input
This is a non-panicking alternative to ensure_positions.
§Returns
Returns Ok(()) if positions are allocated successfully, or Err if
max_pos >= MAX_POSITIONS.
Sourcepub fn test_accuracy(&mut self, data: &[u8]) -> f64
pub fn test_accuracy(&mut self, data: &[u8]) -> f64
Compute reconstruction accuracy (for testing)
Sourcepub fn test_accuracy_chunked(&mut self, data: &[u8], chunk_size: usize) -> f64
pub fn test_accuracy_chunked(&mut self, data: &[u8], chunk_size: usize) -> f64
Compute chunked reconstruction accuracy
Sourcepub fn batch_encode(&mut self, data: &[u8], chunk_size: usize) -> Vec<SparseVec>
pub fn batch_encode(&mut self, data: &[u8], chunk_size: usize) -> Vec<SparseVec>
Batch encode data in parallel using rayon
This method achieves higher throughput by processing chunks in parallel. Position vectors are pre-allocated before parallel processing.
§Arguments
data- Raw bytes to encodechunk_size- Size of each chunk (64 bytes recommended)
§Returns
Vector of encoded chunks, one SparseVec per chunk
§Panics
Panics if chunk_size is 0.
§Example
let mut encoder = ReversibleVSAEncoder::new();
let chunks = encoder.batch_encode(&large_data, 64);Sourcepub fn batch_decode(
&self,
chunks: &[SparseVec],
chunk_size: usize,
total_length: usize,
) -> Vec<u8> ⓘ
pub fn batch_decode( &self, chunks: &[SparseVec], chunk_size: usize, total_length: usize, ) -> Vec<u8> ⓘ
Batch decode chunks in parallel using rayon
This method achieves higher throughput by decoding chunks in parallel.
§Arguments
chunks- Encoded chunks to decodechunk_size- Size of each chunk (must match encoding chunk_size)total_length- Total expected output length
§Returns
Reconstructed bytes
§Panics
Panics if chunk_size is 0.
Sourcepub fn estimate_throughput(data_size: usize, elapsed_secs: f64) -> f64
pub fn estimate_throughput(data_size: usize, elapsed_secs: f64) -> f64
Get throughput statistics for batch encoding
Returns approximate throughput in MB/s based on data size and elapsed time. Useful for benchmarking and optimization.
Returns f64::INFINITY if elapsed_secs is zero or negative.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ReversibleVSAEncoder
impl RefUnwindSafe for ReversibleVSAEncoder
impl Send for ReversibleVSAEncoder
impl Sync for ReversibleVSAEncoder
impl Unpin for ReversibleVSAEncoder
impl UnwindSafe for ReversibleVSAEncoder
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
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>
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>
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