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 <memory>
5#include <optional>
6#include <utility>
7#include <vector>
8
14
15namespace bb::avm2::tracegen {
16
17// Helper to generate a tuple type with N const FF& elements.
18namespace detail {
19template <size_t N, typename = std::make_index_sequence<N>> struct RefTupleHelper;
20template <size_t N, size_t... Is> struct RefTupleHelper<N, std::index_sequence<Is...>> {
21 template <size_t> using ConstFFRef = const FF&;
23};
24} // namespace detail
25template <size_t N> using RefTuple = typename detail::RefTupleHelper<N>::type;
26
27// Same as TraceContainer::get_multiple but copies the values into an owning std::array. Use when
28// the result must outlive a subsequent column write (e.g. when stored as a hash-map key): the
29// references returned by get_multiple point into column storage and can dangle on reallocation.
30template <size_t N>
33 uint32_t row)
34{
35 auto refs = trace.get_multiple(cols, row);
36 return [&]<size_t... Is>(std::index_sequence<Is...>) {
37 return std::array<FF, N>{ flat_tuple::get<Is>(refs)... };
39}
40
42 public:
43 virtual ~InteractionBuilderInterface() = default;
44 virtual void process(TraceContainer& trace) = 0;
45 // Fingerprint of the destination columns.
46 // Used to identify jobs that share the same destination columns and prevent them
47 // from building the index at the same time.
48 virtual size_t get_destination_columns_fingerprint() const { return 0; }
49};
50
51// A concatenate that works with movable objects.
52template <typename T> std::vector<T> concatenate_jobs(std::vector<T>&& first, auto&&... rest)
53{
54 const size_t total_size = first.size() + (rest.size() + ...);
55 std::vector<T> result = std::move(first);
56 result.reserve(total_size);
57 (std::move(rest.begin(), rest.end(), std::back_inserter(result)), ...);
58 return result;
59}
60
61// Orders jobs to minimize index building contention.
62// Jobs with first occurrences of each destination column key come first, followed by jobs that share
63// destination column keys with previously seen ones.
64// This ordering helps the SharedIndexCache by ensuring that when multiple jobs share
65// the same destination, only the first one builds the index while others wait.
67
68} // namespace bb::avm2::tracegen
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