Skip to main content

Batch

Struct Batch 

Source
pub struct Batch<'a> { /* private fields */ }
Expand description

Messages of one length in Blocks, the batch calls’ input: each message starts a block, and every byte past each message’s end is zero, since a Batch lets the program write only the messages’ own bytes (so the bytes the batch kernels read in place, past a message, can never be wrong). It owns its blocks (Batch::new), or borrows blocks already in place whose messages fill them, with no bytes past their ends (Batch::from_blocks: a Merkle layer’s 64-byte nodes, a mapped file’s records).

use blake3_servil_core::{Mode, convenience, throughput::{self, Batch}};
let mut batch = Batch::new(100, 3);
for i in 0..3 {
    batch.set(i, &[i as u8; 100]);
}
let mut out = [[0u8; 32]; 3];
throughput::hash_many(Mode::Plain, &batch, &mut out);
assert_eq!(out[2], *convenience::hash(&[2u8; 100]).as_bytes());

// Read straight into a message's own bytes.
batch.message_mut(1).copy_from_slice(&[9u8; 100]);
throughput::hash_many(Mode::Plain, &batch, &mut out);
assert_eq!(out[1], *convenience::hash(&[9u8; 100]).as_bytes());

§Trait implementations

  • Clone copies owned blocks or shares a read-only borrow, keeping the same messages and padding.
  • Prepared presents the messages in order in whole-block slots, with at least one block per slot.

Implementations§

Source§

impl Batch<'static>

Source

pub fn new(message_len: usize, count: usize) -> Batch<'static>

count messages of message_len bytes, every byte zero. The zeros are written now, so all of a Batch’s memory is resident from its making, not as its pages are first touched: make one and refill it.

Source§

impl<'a> Batch<'a>

Source

pub fn from_blocks(blocks: &'a [Block], message_len: usize) -> Batch<'a>

The messages of message_len bytes that blocks holds, borrowed with no copy, where they fill their blocks: message_len a multiple of 64 (no byte past a message’s end to keep zero; an empty message’s block, which hashing ignores, counts as one), and blocks a whole number of messages (checked here in every build).

Source

pub fn message_len(&self) -> usize

The messages’ length.

Source

pub fn len(&self) -> usize

How many whole messages it holds.

Source

pub fn is_empty(&self) -> bool

Whether it holds no messages.

Source

pub fn blocks(&self) -> &[Block]

Its blocks, as the kernels read them: each message at the start of its blocks, with every byte past a nonempty message’s end zero (a borrowed zero-length batch preserves its caller’s original block bytes, which empty-message hashing ignores).

Source§

impl Batch<'_>

Source

pub fn message_mut(&mut self, i: usize) -> &mut [u8] ⓘ

Message i’s bytes, for writing: message_len of them, no more (a borrowed batch copies its blocks first).

Source

pub fn set(&mut self, i: usize, message: &[u8])

Message i becomes message, message_len bytes.

Source

pub fn messages_mut(&mut self) -> impl ExactSizeIterator

Mutable slices of every message’s own bytes (message_len bytes each), with one copy-on-write check and one stride calculation for the whole batch (BLAKE3 #503).

Every byte past message_len in each block remains inaccessible and untouched (staying zero on owned batches and preserving caller bytes on borrowed zero-length slots), so sub-block batches (such as 32-byte messages) can be refilled in a tight loop without repeating per-element copy-on-write checks.

Source

pub fn blocks_mut(&mut self) -> &mut [Block]

Every byte for writing, where no message has bytes past its end to keep zero: message_len a multiple of 64 and not 0.

Source

pub fn digests_mut(&mut self) -> &mut [[u8; 32]]

Its 64-byte messages as 32-byte digests, two a message: a Merkle layer’s digests written straight into the next layer, whose messages are pairs of children. A layer of an odd count leaves a digest to spare: slice it, &mut batch.digests_mut()[..count].

Trait Implementations§

Source§

impl<'a> Clone for Batch<'a>

Source§

fn clone(&self) -> Batch<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Prepared for Batch<'_>

Source§

fn part(&self, messages: Range<usize>) -> Part<'_>

The messages messages of this batch, as a batch: for a program that hashes a batch in parts (each part on a thread of its own). Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Batch<'a>

§

impl<'a> RefUnwindSafe for Batch<'a>

§

impl<'a> Send for Batch<'a>

§

impl<'a> Sync for Batch<'a>

§

impl<'a> Unpin for Batch<'a>

§

impl<'a> UnsafeUnpin for Batch<'a>

§

impl<'a> UnwindSafe for Batch<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.