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
Clonecopies owned blocks or shares a read-only borrow, keeping the same messages and padding.Preparedpresents the messages in order in whole-block slots, with at least one block per slot.
Implementations§
Source§impl<'a> Batch<'a>
impl<'a> Batch<'a>
Sourcepub fn from_blocks(blocks: &'a [Block], message_len: usize) -> Batch<'a>
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).
Sourcepub fn message_len(&self) -> usize
pub fn message_len(&self) -> usize
The messages’ length.
Source§impl Batch<'_>
impl Batch<'_>
Sourcepub fn message_mut(&mut self, i: usize) -> &mut [u8] ⓘ
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).
Sourcepub fn messages_mut(&mut self) -> impl ExactSizeIterator
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.
Sourcepub fn blocks_mut(&mut self) -> &mut [Block]
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.
Sourcepub fn digests_mut(&mut self) -> &mut [[u8; 32]]
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].