43 trace.visit_column(LookupSettings::SRC_SELECTOR, [&](uint32_t row,
const FF&) {
44 auto src_values =
trace.get_multiple(LookupSettings::SRC_COLUMNS, row);
48 }
catch (
const std::runtime_error& e) {
50 throw std::runtime_error(std::string(e.what()) +
" at row " +
std::to_string(row));
53 trace.set(LookupSettings::COUNTS, dst_row,
trace.get(LookupSettings::COUNTS, dst_row) + 1);
56 trace.
get(LookupSettings::DST_SELECTOR, dst_row) != 1) {
57 trace.set(LookupSettings::DST_SELECTOR, dst_row, 1);
76template <
typename LookupSettings_>
102 LookupSettings::DST_COLUMNS,
112 const auto& rows = it->second;
113 for (uint32_t row : rows) {
119 throw std::runtime_error(
"Failed computing counts for " + std::string(LookupSettings::NAME) +
120 ". Could not find tuple in destination. " +
128 idx.reserve(
trace.get_column_rows(this->outer_dst_selector));
130 auto dst_values =
trace.get_multiple(LookupSettings::DST_COLUMNS, row);
131 size_t key_hash = std::hash<
decltype(dst_values)>{}(dst_values);
133 auto& rows = idx[key_hash];
135 bool found_match =
false;
136 for (uint32_t existing_row : rows) {
137 if (
trace.get_multiple(LookupSettings::DST_COLUMNS, existing_row) == dst_values) {
178 uint32_t dst_row = 0;
183 std::vector<uint32_t> src_rows_in_order;
184 src_rows_in_order.reserve(
trace.get_column_rows(LookupSettings::SRC_SELECTOR));
185 trace.visit_column(LookupSettings::SRC_SELECTOR,
186 [&](uint32_t row,
const FF&) { src_rows_in_order.push_back(row); });
187 std::sort(src_rows_in_order.begin(), src_rows_in_order.end());
189 for (uint32_t row : src_rows_in_order) {
190 auto src_values =
trace.get_multiple(LookupSettings::SRC_COLUMNS, row);
194 while (!found && dst_row < max_dst_row) {
198 if (dst_selector == 1 && src_values ==
trace.get_multiple(LookupSettings::DST_COLUMNS, dst_row)) {
199 trace.set(LookupSettings::COUNTS, dst_row,
trace.get(LookupSettings::COUNTS, dst_row) + 1);
203 trace.
get(LookupSettings::DST_SELECTOR, dst_row) != 1) {
204 trace.set(LookupSettings::DST_SELECTOR, dst_row, 1);
216 throw std::runtime_error(
217 "Failed computing counts for " + std::string(LookupSettings::NAME) +
218 ". Could not find tuple in destination.\nSRC tuple (row " +
std::to_string(row) +
220 "\nNOTE: Remember that you cannot use LookupIntoDynamicTableSequential with a deduplicated trace!");
virtual uint32_t find_in_dst(const TupleType &tup) const =0
LookupSettings_ LookupSettings
virtual void init(TraceContainer &)
Column outer_dst_selector
IndexedLookupTraceBuilder(Column outer_dst_selector)
RefTuple< LookupSettings::LOOKUP_TUPLE_SIZE > TupleType
~IndexedLookupTraceBuilder() override=default
void process(TraceContainer &trace) override
IndexedLookupTraceBuilder()
LookupIntoDynamicTableGeneric(SharedIndexCache &cache, Column outer_dst_selector)
const TraceContainer * trace_ptr_
virtual ~LookupIntoDynamicTableGeneric()=default
const DstIndex * index_ptr_
LookupSettings_ LookupSettings
RefTuple< LookupSettings::LOOKUP_TUPLE_SIZE > TupleType
uint32_t find_in_dst(const TupleType &tup) const override
DstIndex build_index(const TraceContainer &trace)
LookupIntoDynamicTableGeneric(SharedIndexCache &cache)
void init(TraceContainer &trace) override
SharedIndexCache & cache_
size_t get_destination_columns_fingerprint() const override
LookupIntoDynamicTableSequential()
~LookupIntoDynamicTableSequential() override=default
Column outer_dst_selector
LookupIntoDynamicTableSequential(Column outer_dst_selector)
void process(TraceContainer &trace) override
const DstIndex & get_or_build(Column outer_dst_selector, std::span< const ColumnAndShifts > dst_columns, const TraceContainer &trace, std::function< DstIndex(const TraceContainer &)> build_fn)
const FF & get(Column col, uint32_t row) const
auto get_multiple(const std::array< ColumnAndShifts, N > &cols, uint32_t row) const
typename detail::RefTupleHelper< N >::type RefTuple
unordered_flat_map< size_t, std::vector< uint32_t > > DstIndex
std::string column_values_to_string(const std::array< FF, N > &arr, const std::array< ColumnAndShifts, N > &columns)
size_t hash_as_tuple(const Ts &... ts)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)