FieldBuffer

Struct FieldBuffer 

Source
pub struct FieldBuffer<P: PackedField, Data: Deref<Target = [P]> = Box<[P]>> { /* private fields */ }
Expand description

A power-of-two-sized buffer containing field elements, stored in packed fields.

This struct maintains a set of invariants:

  1. values.len() is a power of two
  2. values.len() >= 1 << log_len.saturating_sub(P::LOG_WIDTH).

Implementations§

Source§

impl<P: PackedField> FieldBuffer<P>

Source

pub fn from_values(values: &[P::Scalar]) -> Self

Create a new FieldBuffer from a vector of values.

§Preconditions
  • values.len() must be a power of two.
Source

pub fn from_values_truncated(values: &[P::Scalar], log_cap: usize) -> Self

Create a new FieldBuffer from a vector of values.

Capacity log_cap is bumped to at least P::LOG_WIDTH.

§Preconditions
  • values.len() must be a power of two.
  • values.len() must not exceed 1 << log_cap.
Source

pub fn zeros(log_len: usize) -> Self

Create a new FieldBuffer of zeros with the given log_len.

Source

pub fn zeros_truncated(log_len: usize, log_cap: usize) -> Self

Create a new FieldBuffer of zeros with the given log_len and capacity log_cap.

Capacity log_cap is bumped to at least P::LOG_WIDTH.

§Preconditions
  • log_len must not exceed log_cap.
Source§

impl<P: PackedField, Data: Deref<Target = [P]>> FieldBuffer<P, Data>

Source

pub fn new(log_len: usize, values: Data) -> Self

Create a new FieldBuffer from a slice of packed values.

§Preconditions
  • values.len() must equal the expected packed length for log_len.
Source

pub fn new_truncated(log_len: usize, values: Data) -> Self

Create a new FieldBuffer from a slice of packed values.

§Preconditions
  • values.len() must be at least the minimum packed length for log_len.
  • values.len() must be a power of two.
Source

pub fn log_cap(&self) -> usize

Returns log2 the number of field elements that the underlying collection may take.

Source

pub fn cap(&self) -> usize

Returns the number of field elements that the underlying collection may take.

Source

pub const fn log_len(&self) -> usize

Returns log2 the number of field elements.

Source

pub fn len(&self) -> usize

Returns the number of field elements.

Source

pub fn to_ref(&self) -> FieldSlice<'_, P>

Borrows the buffer as a FieldSlice.

Source

pub fn get(&self, index: usize) -> P::Scalar

Get a field element at the given index.

§Preconditions
  • the index is in the range 0..self.len()
Source

pub fn iter_scalars( &self, ) -> impl Iterator<Item = P::Scalar> + Send + Clone + '_

Returns an iterator over the scalar elements in the buffer.

Source

pub fn chunk( &self, log_chunk_size: usize, chunk_index: usize, ) -> FieldSlice<'_, P>

Get an aligned chunk of size 2^log_chunk_size.

Chunk start offset divides chunk size; the result is essentially chunks(log_chunk_size).nth(chunk_index) but unlike chunks it does support sizes smaller than packing width.

§Preconditions
  • log_chunk_size must be at most log_len.
  • chunk_index must be less than the chunk count.
Source

pub fn chunks( &self, log_chunk_size: usize, ) -> impl Iterator<Item = FieldSlice<'_, P>> + Clone

Split the buffer into chunks of size 2^log_chunk_size.

§Preconditions
  • log_chunk_size must be at least P::LOG_WIDTH and at most log_len.
Source

pub fn chunks_par( &self, log_chunk_size: usize, ) -> impl IndexedParallelIterator<Item = FieldSlice<'_, P>>

Creates an iterator over chunks of size 2^log_chunk_size in parallel.

§Preconditions
  • log_chunk_size must be at most log_len.
Source

pub fn split_half_ref(&self) -> (FieldSlice<'_, P>, FieldSlice<'_, P>)

Splits the buffer in half and returns a pair of borrowed slices.

§Preconditions
  • self.log_len() must be greater than 0.
Source§

impl<P: PackedField, Data: DerefMut<Target = [P]>> FieldBuffer<P, Data>

Source

pub fn to_mut(&mut self) -> FieldSliceMut<'_, P>

Borrows the buffer mutably as a FieldSliceMut.

Source

pub fn set(&mut self, index: usize, value: P::Scalar)

Set a field element at the given index.

§Preconditions
  • the index is in the range 0..self.len()
Source

pub fn truncate(&mut self, new_log_len: usize)

Truncates a field buffer to a shorter length.

If new_log_len is not less than current log_len(), this has no effect.

Source

pub fn zero_extend(&mut self, new_log_len: usize)

Zero extends a field buffer to a longer length.

If new_log_len is not greater than current log_len(), this has no effect.

§Preconditions
  • new_log_len must not exceed the buffer’s capacity.
Source

pub fn resize(&mut self, new_log_len: usize)

Sets the new log length. If the new log length is bigger than the current log length, the new values (in case when self.log_len < new_log_len) will be filled with the values from the existing buffer.

§Preconditions
  • new_log_len must not exceed the buffer’s capacity.
Source

pub fn chunks_mut( &mut self, log_chunk_size: usize, ) -> impl Iterator<Item = FieldSliceMut<'_, P>>

Split the buffer into mutable chunks of size 2^log_chunk_size.

§Preconditions
  • log_chunk_size must be at least P::LOG_WIDTH and at most log_len.
Source

pub fn chunk_mut( &mut self, log_chunk_size: usize, chunk_index: usize, ) -> FieldBufferChunkMut<'_, P>

Get a mutable aligned chunk of size 2^log_chunk_size.

This method behaves like FieldBuffer::chunk but returns a mutable reference. For small chunks (log_chunk_size < P::LOG_WIDTH), this returns a wrapper that implements deferred writes - modifications are written back when the wrapper is dropped.

§Preconditions
  • log_chunk_size must be at most log_len.
  • chunk_index must be less than the chunk count.
Source

pub fn split_half(self) -> FieldBufferSplitMut<P, Data>

Consumes the buffer and splits it in half, returning a FieldBufferSplitMut.

This returns an object that owns the buffer data and can be used to access mutable references to the two halves. If the buffer contains a single packed element that needs to be split, the returned struct will create temporary copies and write the results back to the original buffer when dropped.

§Preconditions
  • self.log_len() must be greater than 0.
Source

pub fn split_half_mut(&mut self) -> FieldBufferSplitMut<P, &mut [P]>

Splits the buffer in half and returns a FieldBufferSplitMut for accessing the halves.

This is a convenience method equivalent to self.to_mut().split_half().

§Preconditions
  • self.log_len() must be greater than 0.
Source§

impl<'a, P: PackedField> FieldBuffer<P, FieldSliceData<'a, P>>

Source

pub fn from_slice(log_len: usize, slice: &'a [P]) -> Self

Create a new FieldSlice from a slice of packed values.

§Preconditions
  • slice.len() must equal the expected packed length for log_len.
Source§

impl<'a, P: PackedField> FieldBuffer<P, &'a mut [P]>

Source

pub fn from_slice(log_len: usize, slice: &'a mut [P]) -> Self

Create a new FieldSliceMut from a mutable slice of packed values.

§Preconditions
  • slice.len() must equal the expected packed length for log_len.

Trait Implementations§

Source§

impl<P: PackedField, Data: DerefMut<Target = [P]>> AsMut<[P]> for FieldBuffer<P, Data>

Source§

fn as_mut(&mut self) -> &mut [P]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<P: PackedField, Data: Deref<Target = [P]>> AsRef<[P]> for FieldBuffer<P, Data>

Source§

fn as_ref(&self) -> &[P]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<P: Clone + PackedField, Data: Clone + Deref<Target = [P]>> Clone for FieldBuffer<P, Data>

Source§

fn clone(&self) -> FieldBuffer<P, Data>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + PackedField, Data: Debug + Deref<Target = [P]>> Debug for FieldBuffer<P, Data>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, P: PackedField, Data: Deref<Target = [P]>> From<&'a FieldBuffer<P, Data>> for FieldSlice<'a, P>

Source§

fn from(buffer: &'a FieldBuffer<P, Data>) -> Self

Converts to this type from the input type.
Source§

impl<'a, P: PackedField, Data: DerefMut<Target = [P]>> From<&'a mut FieldBuffer<P, Data>> for FieldSliceMut<'a, P>

Source§

fn from(buffer: &'a mut FieldBuffer<P, Data>) -> Self

Converts to this type from the input type.
Source§

impl<F: Field, Data: Deref<Target = [F]>> Index<usize> for FieldBuffer<F, Data>

Source§

type Output = F

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<F: Field, Data: DerefMut<Target = [F]>> IndexMut<usize> for FieldBuffer<F, Data>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<P: PackedField, Data: Deref<Target = [P]>> PartialEq for FieldBuffer<P, Data>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: Eq + PackedField, Data: Eq + Deref<Target = [P]>> Eq for FieldBuffer<P, Data>

Auto Trait Implementations§

§

impl<P, Data> Freeze for FieldBuffer<P, Data>
where Data: Freeze,

§

impl<P, Data> RefUnwindSafe for FieldBuffer<P, Data>
where Data: RefUnwindSafe,

§

impl<P, Data> Send for FieldBuffer<P, Data>
where Data: Send,

§

impl<P, Data> Sync for FieldBuffer<P, Data>
where Data: Sync,

§

impl<P, Data> Unpin for FieldBuffer<P, Data>
where Data: Unpin,

§

impl<P, Data> UnwindSafe for FieldBuffer<P, Data>
where Data: UnwindSafe,

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

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> 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more