Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
interaction_builder.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <iterator>
7#include <memory>
8#include <utility>
9#include <vector>
10
15
16namespace bb::avm2::tracegen {
17
18// Helper to generate a tuple type with N const FF& elements.
19namespace detail {
20template <size_t N, typename = std::make_index_sequence<N>> struct RefTupleHelper;
21template <size_t N, size_t... Is> struct RefTupleHelper<N, std::index_sequence<Is...>> {
22 template <size_t> using ConstFFRef = const FF&;
24};
25} // namespace detail
26
27template <size_t N> using RefTuple = typename detail::RefTupleHelper<N>::type;
28
29// Same as TraceContainer::get_multiple but copies the values into an owning std::array. Use when
30// the result must outlive a subsequent column write (e.g. when stored as a hash-map key): the
31// references returned by get_multiple point into column storage and can dangle on reallocation.
32template <size_t N>
35 uint32_t row)
36{
37 auto refs = trace.get_multiple(cols, row);
38 return [&]<size_t... Is>(std::index_sequence<Is...>) {
39 return std::array<FF, N>{ flat_tuple::get<Is>(refs)... };
41}
42
44 public:
45 virtual ~InteractionBuilderInterface() = default;
46 virtual void process(TraceContainer& trace) = 0;
47 // Fingerprint of the destination columns.
48 // Used to identify jobs that share the same destination columns and prevent them
49 // from building the index at the same time.
50 virtual size_t get_destination_columns_fingerprint() const { return 0; }
51};
52
53// A concatenate that works with movable objects.
54template <typename T> std::vector<T> concatenate_jobs(std::vector<T>&& first, auto&&... rest)
55{
56 const size_t total_size = first.size() + (rest.size() + ...);
58 result.reserve(total_size);
59 (std::move(rest.begin(), rest.end(), std::back_inserter(result)), ...);
60 return result;
61}
62
63// Orders jobs to minimize index building contention.
64// Jobs with first occurrences of each destination column key come first, followed by jobs that share
65// destination column keys with previously seen ones.
66// This ordering helps the SharedIndexCache by ensuring that when multiple jobs share
67// the same destination, only the first one builds the index while others wait.
69
70} // namespace bb::avm2::tracegen
constexpr size_t N
virtual void process(TraceContainer &trace)=0
auto get_multiple(const std::array< ColumnAndShifts, N > &cols, uint32_t row) const
TestTraceContainer trace
std::array< FF, N > get_multiple_as_array(const TraceContainer &trace, const std::array< ColumnAndShifts, N > &cols, uint32_t row)
typename detail::RefTupleHelper< N >::type RefTuple
void order_jobs_by_destination_columns(std::vector< std::unique_ptr< InteractionBuilderInterface > > &jobs)
std::vector< T > concatenate_jobs(std::vector< T > &&first, auto &&... rest)
AvmFlavorSettings::FF FF
Definition field.hpp:10
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
TUPLET_INLINE constexpr decltype(auto) get(Tup &&tup)
Definition tuplet.hpp:1021
VectorField result