Skip to main content

ReversibleVSAEncoder

Struct ReversibleVSAEncoder 

Source
pub struct ReversibleVSAEncoder { /* private fields */ }
Expand description

Reversible encoder using position-aware VSA binding

Implementations§

Source§

impl ReversibleVSAEncoder

Source

pub fn new() -> Self

Create a new reversible encoder

Source

pub fn with_dim(dim: usize) -> Self

Create a new reversible encoder with custom dimensionality

Source

pub fn encode(&mut self, data: &[u8]) -> SparseVec

Encode data into a holographic representation

Returns a single SparseVec that contains all the data holographically.

Source

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.

Source

pub fn decode(&self, encoded: &SparseVec, length: usize) -> Vec<u8>

Decode data from a holographic representation

Uses bind + similarity search to retrieve each byte.

Source

pub fn decode_chunked( &self, chunks: &[SparseVec], chunk_size: usize, total_length: usize, ) -> Vec<u8>

Decode chunked data

§Panics

Panics if chunk_size is 0.

Source

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.

Source

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.

Source

pub fn ensure_positions(&mut self, max_pos: usize)

Ensure position vectors exist up to (and including) the given position

§Panics

Panics if max_pos >= MAX_POSITIONS (65536).

§Example
let mut encoder = ReversibleVSAEncoder::new();
encoder.ensure_positions(1000); // OK
// encoder.ensure_positions(100000); // Would panic
Source

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.

Source

pub fn test_accuracy(&mut self, data: &[u8]) -> f64

Compute reconstruction accuracy (for testing)

Source

pub fn test_accuracy_chunked(&mut self, data: &[u8], chunk_size: usize) -> f64

Compute chunked reconstruction accuracy

Source

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 encode
  • chunk_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);
Source

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 decode
  • chunk_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.

Source

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§

Source§

impl Default for ReversibleVSAEncoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V