Barretenberg
The ZK-SNARK library at the core of Aztec
|
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. | |
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.
T | The type of the elements in the array. |
Definition at line 29 of file shared_shifted_virtual_zeroes_array.hpp.
|
inline |
Returns a pointer to the underlying memory array. NOTE: This should be used with care, as index 0 corresponds to virtual index start_
.
Definition at line 80 of file shared_shifted_virtual_zeroes_array.hpp.
|
inline |
Definition at line 81 of file shared_shifted_virtual_zeroes_array.hpp.
|
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.
index | The index from which to retrieve the value. |
virtual_padding | For the rare case where we explicitly want the 0-returning behavior beyond our usual virtual_size. |
Fails | in 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.
|
inline |
Definition at line 88 of file shared_shifted_virtual_zeroes_array.hpp.
|
inline |
Definition at line 94 of file shared_shifted_virtual_zeroes_array.hpp.
|
inline |
Definition at line 101 of file shared_shifted_virtual_zeroes_array.hpp.
|
inline |
Sets the value at the specified index.
index | The index at which the value should be set. |
value | The value to set. |
Fails | in 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.
|
inline |
Definition at line 84 of file shared_shifted_virtual_zeroes_array.hpp.
|
inline |
Definition at line 86 of file shared_shifted_virtual_zeroes_array.hpp.
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.
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.
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.
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.