Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
shared_shifted_virtual_zeroes_array.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
12#include <cstddef>
13#include <memory>
14
29template <typename T> struct SharedShiftedVirtualZeroesArray {
30
38 void set(size_t index, const T& value)
39 {
40 ASSERT_DEBUG(index >= start_);
41 ASSERT_DEBUG(index < end_);
42 data()[index - start_] = value;
43 }
44
56 const T& get(size_t index, size_t virtual_padding = 0) const
57 {
58 static const T zero{};
60 if (index >= start_ && index < end_) {
61 return data()[index - start_];
62 }
63 return zero; // Return default element when index is out of the actual filled size
64 }
65
72 T* data() { return backing_memory_.raw_data; }
73 const T* data() const { return backing_memory_.raw_data; }
74 // Our size is end_ - start_. Note that we need to offset end_ when doing a shift to
75 // correctly maintain the size.
76 size_t size() const { return end_ - start_; }
77 // Getter for consistency with size();
78 size_t virtual_size() const { return virtual_size_; }
79
81 {
82 BB_ASSERT_GTE(new_virtual_size, virtual_size_); // shrinking is not allowed
84 }
85
86 T& operator[](size_t index)
87 {
88 ASSERT_DEBUG(index >= start_);
89 ASSERT_DEBUG(index < end_);
90 return data()[index - start_];
91 }
92 // get() is more useful, but for completeness with the non-const operator[]
93 const T& operator[](size_t index) const
94 {
95 ASSERT_DEBUG(index >= start_);
96 ASSERT_DEBUG(index < end_);
97 return data()[index - start_];
98 }
99
100 // MEMBERS:
110 size_t start_ = 0;
111
119 size_t end_ = 0;
120
127 size_t virtual_size_ = 0;
128
136};
#define BB_ASSERT_GTE(left, right,...)
Definition assert.hpp:133
#define ASSERT_DEBUG(expression,...)
Definition assert.hpp:54
A shared pointer array template that represents a virtual array filled with zeros up to virtual_size_...
size_t start_
The starting index of the memory-backed range.
BackingMemory< T > backing_memory_
The underlying memory storage.
void increase_virtual_size(const size_t new_virtual_size)
T * data()
Returns a pointer to the underlying memory array. NOTE: This should be used with care,...
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...
void set(size_t index, const T &value)
Sets the value at the specified index.
size_t virtual_size_
The total logical size of the array.
size_t end_
The ending index of the memory-backed range.