Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
SharedShiftedVirtualZeroesArray< T > Struct Template Reference

A shared pointer array template that represents a virtual array filled with zeros up to virtual_size_, but with actual memory usage proportional to the region between start_ and end_. More...

#include <shared_shifted_virtual_zeroes_array.hpp>

Public Member Functions

void set (size_t index, const T &value)
 Sets the value at the specified index.
 
const T & get (size_t index, size_t virtual_padding=0) const
 Retrieves the value at the specified index, or 'zero'. Optimizes for e.g. 256-bit fields by storing a static 0 value, allowing usage of a const reference.
 
T * data ()
 Returns a pointer to the underlying memory array. NOTE: This should be used with care, as index 0 corresponds to virtual index start_.
 
const T * data () const
 
size_t size () const
 
size_t virtual_size () const
 
void increase_virtual_size (const size_t new_virtual_size)
 
T & operator[] (size_t index)
 
const T & operator[] (size_t index) const
 

Public Attributes

size_t start_ = 0
 The starting index of the memory-backed range.
 
size_t end_ = 0
 The ending index of the memory-backed range.
 
size_t virtual_size_ = 0
 The total logical size of the array.
 
std::shared_ptr< BackingMemory< T > > backing_memory_
 Shared pointer to the underlying memory array.
 

Detailed Description

template<typename T>
struct SharedShiftedVirtualZeroesArray< T >

A shared pointer array template that represents a virtual array filled with zeros up to virtual_size_, but with actual memory usage proportional to the region between start_ and end_.

This structure is designed to optimize memory usage by only allocating memory for a specific subrange of the array. The start_ and end_ members define the range of indices that are backed by actual memory. The rest of the indices, up to virtual_size_, are conceptually filled with zero values.

The class allows for sharing the underlying array with potential offset adjustments, making it possible to represent shifted arrays where the actual memory-backed range starts from a non-zero index. It is designed to be wrapped by another class, namely Polynomial, and is not intended to be used directly.

Template Parameters
TThe type of the elements in the array.

Definition at line 29 of file shared_shifted_virtual_zeroes_array.hpp.

Member Function Documentation

◆ data() [1/2]

template<typename T >
T * SharedShiftedVirtualZeroesArray< T >::data ( )
inline

Returns a pointer to the underlying memory array. NOTE: This should be used with care, as index 0 corresponds to virtual index start_.

Returns
A pointer to the beginning of the memory-backed range.

Definition at line 80 of file shared_shifted_virtual_zeroes_array.hpp.

◆ data() [2/2]

template<typename T >
const T * SharedShiftedVirtualZeroesArray< T >::data ( ) const
inline

Definition at line 81 of file shared_shifted_virtual_zeroes_array.hpp.

◆ get()

template<typename T >
const T & SharedShiftedVirtualZeroesArray< T >::get ( size_t  index,
size_t  virtual_padding = 0 
) const
inline

Retrieves the value at the specified index, or 'zero'. Optimizes for e.g. 256-bit fields by storing a static 0 value, allowing usage of a const reference.

Parameters
indexThe index from which to retrieve the value.
virtual_paddingFor the rare case where we explicitly want the 0-returning behavior beyond our usual virtual_size.
Returns
The value at the specified index, or a default value (e.g. a field zero) of T if the index is outside the memory-backed range.
Exceptions
Failsin assert mode if the index is greater than or equal to virtual_size_.

Definition at line 56 of file shared_shifted_virtual_zeroes_array.hpp.

◆ increase_virtual_size()

template<typename T >
void SharedShiftedVirtualZeroesArray< T >::increase_virtual_size ( const size_t  new_virtual_size)
inline

Definition at line 88 of file shared_shifted_virtual_zeroes_array.hpp.

◆ operator[]() [1/2]

template<typename T >
T & SharedShiftedVirtualZeroesArray< T >::operator[] ( size_t  index)
inline

Definition at line 94 of file shared_shifted_virtual_zeroes_array.hpp.

◆ operator[]() [2/2]

template<typename T >
const T & SharedShiftedVirtualZeroesArray< T >::operator[] ( size_t  index) const
inline

Definition at line 101 of file shared_shifted_virtual_zeroes_array.hpp.

◆ set()

template<typename T >
void SharedShiftedVirtualZeroesArray< T >::set ( size_t  index,
const T &  value 
)
inline

Sets the value at the specified index.

Parameters
indexThe index at which the value should be set.
valueThe value to set.
Exceptions
Failsin assert mode if the index is not within the memory-backed range [start_, end_).

Definition at line 38 of file shared_shifted_virtual_zeroes_array.hpp.

◆ size()

template<typename T >
size_t SharedShiftedVirtualZeroesArray< T >::size ( ) const
inline

Definition at line 84 of file shared_shifted_virtual_zeroes_array.hpp.

◆ virtual_size()

template<typename T >
size_t SharedShiftedVirtualZeroesArray< T >::virtual_size ( ) const
inline

Definition at line 86 of file shared_shifted_virtual_zeroes_array.hpp.

Member Data Documentation

◆ backing_memory_

template<typename T >
std::shared_ptr<BackingMemory<T> > SharedShiftedVirtualZeroesArray< T >::backing_memory_

Shared pointer to the underlying memory array.

The memory is allocated for at least the range [start_, end_). It is shared across instances to allow for efficient memory use when arrays are shifted or otherwise manipulated.

Definition at line 143 of file shared_shifted_virtual_zeroes_array.hpp.

◆ end_

template<typename T >
size_t SharedShiftedVirtualZeroesArray< T >::end_ = 0

The ending index of the memory-backed range.

Represents the first index after start_ that is not backed by actual memory. Note however that the backed memory might extend beyond end_ index but will not be accessed anymore. Namely, any access after after end_ returns zero. (Happens after Polynomial::shrink_end_index() call).

Definition at line 127 of file shared_shifted_virtual_zeroes_array.hpp.

◆ start_

template<typename T >
size_t SharedShiftedVirtualZeroesArray< T >::start_ = 0

The starting index of the memory-backed range.

Represents the first index in the array that is backed by actual memory. This is used to represent polynomial shifts by representing the unshfited polynomials with index >= 1 and reducing this by one to divide by x / left shift one. Historically, we used memory padding to represent shifts. This is currently implied by start_ (before which we consider all values 0).

Definition at line 118 of file shared_shifted_virtual_zeroes_array.hpp.

◆ virtual_size_

template<typename T >
size_t SharedShiftedVirtualZeroesArray< T >::virtual_size_ = 0

The total logical size of the array.

This is the size of the array as it would appear to a user, including both the memory-backed range and the conceptual zero-filled range beyond end_ and before start_ (if a positive value).

Definition at line 135 of file shared_shifted_virtual_zeroes_array.hpp.


The documentation for this struct was generated from the following file: