BatchProcessor

Struct BatchProcessor 

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

High-performance batch processor for parallel operations

Provides parallel processing of multiple blocks, CIDs, and hash computations using Rayon’s thread pool.

Implementations§

Source§

impl BatchProcessor

Source

pub fn new() -> Self

Create a new batch processor with default settings (SHA2-256)

Source

pub fn with_hash_algorithm(hash_algorithm: HashAlgorithm) -> Self

Create a batch processor with a specific hash algorithm

Source

pub fn create_blocks_parallel( &self, data_chunks: Vec<Bytes>, ) -> Result<Vec<Block>>

Create multiple blocks in parallel from data chunks

This is significantly faster than creating blocks sequentially when processing many chunks.

Source

pub fn generate_cids_parallel( &self, data_chunks: Vec<Bytes>, ) -> Result<Vec<(Bytes, Cid)>>

Generate CIDs in parallel for multiple data chunks

Returns a vector of (data, CID) pairs.

Source

pub fn verify_blocks_parallel(&self, blocks: &[Block]) -> Result<()>

Verify multiple blocks in parallel

Returns Ok(()) if all blocks are valid, or an error for the first invalid block.

Source

pub fn compute_hashes_parallel( &self, data_chunks: &[&[u8]], ) -> Result<Vec<Vec<u8>>>

Compute hashes in parallel for multiple data chunks

Returns a vector of hash digests.

Source

pub fn total_bytes_parallel(&self, blocks: &[Block]) -> usize

Count total bytes across multiple blocks in parallel

Source

pub fn filter_blocks_parallel<F>( &self, blocks: Vec<Block>, predicate: F, ) -> Vec<Block>
where F: Fn(&Block) -> bool + Sync + Send,

Find blocks matching a predicate in parallel

Source

pub fn unique_cids_parallel(&self, blocks: &[Block]) -> Vec<Cid>

Collect unique CIDs from blocks in parallel

Source

pub fn compress_data_parallel( &self, data_chunks: Vec<Bytes>, algorithm: CompressionAlgorithm, level: u8, ) -> Result<Vec<Bytes>>

Compress multiple data chunks in parallel

Compresses each data chunk using the specified algorithm and level. Returns a vector of compressed data, maintaining the same order as input.

§Arguments
  • data_chunks - Vector of data chunks to compress
  • algorithm - Compression algorithm to use
  • level - Compression level (0-9)
§Returns

Vector of compressed data chunks

§Example
use ipfrs_core::batch::BatchProcessor;
use ipfrs_core::CompressionAlgorithm;
use bytes::Bytes;

let processor = BatchProcessor::new();
let data = vec![
    Bytes::from(vec![0u8; 1000]),
    Bytes::from(vec![1u8; 1000]),
];

let compressed = processor.compress_data_parallel(
    data,
    CompressionAlgorithm::Zstd,
    3
).unwrap();
assert_eq!(compressed.len(), 2);
Source

pub fn decompress_data_parallel( &self, compressed_chunks: Vec<Bytes>, algorithm: CompressionAlgorithm, ) -> Result<Vec<Bytes>>

Decompress multiple compressed chunks in parallel

Decompresses each chunk using the specified algorithm. Returns a vector of decompressed data, maintaining the same order as input.

§Arguments
  • compressed_chunks - Vector of compressed data chunks
  • algorithm - Compression algorithm that was used
§Returns

Vector of decompressed data chunks

§Example
use ipfrs_core::batch::BatchProcessor;
use ipfrs_core::CompressionAlgorithm;
use bytes::Bytes;

let processor = BatchProcessor::new();
let data = vec![Bytes::from(vec![0u8; 1000])];

let compressed = processor.compress_data_parallel(
    data.clone(),
    CompressionAlgorithm::Lz4,
    3
).unwrap();

let decompressed = processor.decompress_data_parallel(
    compressed,
    CompressionAlgorithm::Lz4
).unwrap();
assert_eq!(decompressed, data);
Source

pub fn analyze_compression_ratios_parallel( &self, data_chunks: &[Bytes], algorithm: CompressionAlgorithm, level: u8, ) -> Result<Vec<f64>>

Analyze compression ratios for multiple data chunks in parallel

Computes compression ratio estimates for each chunk. Returns a vector of ratios (compressed_size / original_size), where lower is better.

§Arguments
  • data_chunks - Vector of data chunks to analyze
  • algorithm - Compression algorithm to use for estimation
  • level - Compression level (0-9)
§Returns

Vector of compression ratios (0.0 to 1.0, where 0.5 means 50% size reduction)

§Example
use ipfrs_core::batch::BatchProcessor;
use ipfrs_core::CompressionAlgorithm;
use bytes::Bytes;

let processor = BatchProcessor::new();
let data = vec![
    Bytes::from(vec![0u8; 1000]), // Highly compressible
    Bytes::from(vec![1u8; 1000]), // Highly compressible
];

let ratios = processor.analyze_compression_ratios_parallel(
    &data,
    CompressionAlgorithm::Zstd,
    3
).unwrap();
assert_eq!(ratios.len(), 2);
// Repetitive data should compress well (ratio < 0.5)
assert!(ratios[0] < 0.5);

Trait Implementations§

Source§

impl Default for BatchProcessor

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

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,