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]) -> Result<Self, Error>

Create a new FieldBuffer from a vector of values.

§Throws
  • PowerOfTwoLengthRequired if the number of values is not a power of two.
Source

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

Create a new FieldBuffer from a vector of values.

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

§Throws
  • PowerOfTwoLengthRequired if the number of values is not a power of two.
  • IncorrectArgumentLength if the number of values exceeds 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) -> Result<Self, Error>

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.

Source§

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

Source

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

Create a new FieldBuffer from a slice of packed values.

§Throws
  • IncorrectArgumentLength if the number of field elements does not fit the values.len() exactly.
Source

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

Create a new FieldBuffer from a slice of packed values.

§Throws
  • IncorrectArgumentLength if the number of field elements does not fit into the values.
  • PowerOfTwoLengthRequired if the values.len() is not 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 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) -> Result<P::Scalar, Error>

Get a field element at the given index.

§Throws
  • Error::ArgumentRangeError if the index is out of bounds.
Source

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

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.

Source

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

Split the buffer into chunks of size 2^log_chunk_size.

§Errors
Source

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

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

§Throws
Source

pub fn split_half( &self, ) -> Result<(FieldSlice<'_, P>, FieldSlice<'_, P>), Error>

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

§Throws
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) -> Result<(), Error>

Set a field element at the given index.

§Throws
  • Error::ArgumentRangeError if the index is out of bounds.
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) -> Result<(), Error>

Zero extends a field buffer to a longer length.

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

§Throws
  • Error::IncorrectArgumentLength if the zero extended size exceeds underlying capacity.
Source

pub fn resize(&mut self, new_log_len: usize) -> Result<(), Error>

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.

§Throws
  • Error::IncorrectArgumentLength if the new log length exceeds the buffer’s capacity.
Source

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

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

§Throws
Source

pub fn split_half_mut<F, R>(&mut self, f: F) -> Result<R, Error>
where F: FnOnce(&mut FieldSliceMut<'_, P>, &mut FieldSliceMut<'_, P>) -> R,

Splits the buffer in half and calls a closure with the two halves.

If the buffer contains a single packed element that needs to be split, this method will create temporary copies, call the closure, and then write the results back to the original buffer.

§Throws
Source

pub fn split_half_mut_no_closure( &mut self, ) -> Result<FieldBufferSplitMut<'_, P>, Error>

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

This returns an object that can be used to access mutable references to the two halves. This method unfortunately can’t simply return a tuple of slices because the buffer may have only one packed element. If the buffer contains a single packed element that needs to be split, this method will create temporary copies, call the closure, and then write the results back to the original buffer when the returned FieldBufferSplitMut is dropped.

§Throws
Source§

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

Source

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

Create a new FieldSlice from a slice of packed values.

§Throws
  • IncorrectArgumentLength if the number of field elements does not fit the slice.len() exactly.
Source§

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

Source

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

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

§Throws
  • IncorrectArgumentLength if the number of field elements does not fit the slice.len() exactly.

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

impl<T> AsMaybeUninit for T

§

type Uninit = MaybeUninit<T>

This type in its maybe-uninitialized form.
§

type SizedPart = T

The largest Sized element in Self, used to check for the absence of drop glue via a Copy bound. Read more
§

fn as_ref_uninit(&self) -> &<T as AsMaybeUninit>::Uninit

Converts a &self to its maybe-initialized equivalent.
§

unsafe fn as_mut_uninit(&mut self) -> &mut <T as AsMaybeUninit>::Uninit

Converts a &mut T to its maybe-initialized equivalent. Read more
§

unsafe fn raw_as_uninit<'a>(raw: *const T) -> &'a <T as AsMaybeUninit>::Uninit

Converts a raw pointer to a reference to maybe-uninit. Read more
§

unsafe fn raw_mut_as_uninit<'a>( raw: *mut T, ) -> &'a mut <T as AsMaybeUninit>::Uninit

Converts a raw mutable pointer to a mutable reference to maybe-uninit. 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> ManuallyDropMut for T

§

type Ret = ManuallyDrop<T>

§

fn manually_drop_mut<'__>(&'__ mut self) -> &'__ mut ManuallyDrop<T>

§

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