2#include "../bool/bool.hpp"
3#include "../safe_uint/safe_uint.hpp"
17 bool_t<Builder> hit_zero =
false;
18 for (
const auto& e : arr) {
19 bool_t<Builder> is_zero = e.is_zero();
20 hit_zero.must_imply(is_zero,
"Once we've hit the first zero, there must only be zeros thereafter!");
37 bool_t<Builder> already_popped =
false;
38 for (
size_t i = arr.size() - 1; i != (
size_t)-1; i--) {
39 bool_t<Builder> is_non_zero = arr[i] != 0;
42 already_popped |= is_non_zero;
44 already_popped.assert_equal(
true,
"array_pop cannot pop from an empty array");
53template <
typename Builder,
size_t SIZE>
56 bool_t<Builder> already_pushed =
false;
57 for (
size_t i = 0; i < arr.size(); ++i) {
58 bool_t<Builder> is_zero = arr[i] == 0;
61 already_pushed |= is_zero;
63 already_pushed.assert_equal(
true,
"array_push cannot push to a full array");
70template <
typename Builder,
size_t SIZE>
73 for (
size_t i = 0; i < arr.size(); ++i) {
74 if (arr[i] == std::nullopt) {
79 throw_or_abort(
"array_push cannot push to a full array");
86template <
typename T,
size_t SIZE>
87inline size_t array_push(std::array<std::shared_ptr<T>, SIZE>& arr, std::shared_ptr<T>
const& value)
89 for (
size_t i = 0; i < arr.size(); ++i) {
90 if (arr[i] ==
nullptr) {
95 throw_or_abort(
"array_push cannot push to a full array");
102template <
typename Builder,
typename T,
size_t SIZE>
inline void array_push(std::array<T, SIZE>& arr, T
const& value)
104 bool_t<Builder> already_pushed =
false;
105 for (
size_t i = 0; i < arr.size(); ++i) {
106 bool_t<Builder> is_zero = arr[i].is_empty();
107 arr[i].conditional_select(!already_pushed && is_zero, value);
109 already_pushed |= is_zero;
111 already_pushed.assert_equal(
true,
"array_push cannot push to a full array");
118template <
typename Builder,
size_t SIZE>
119typename plonk::stdlib::bool_t<Builder> is_array_empty(std::array<
field_t<Builder>, SIZE>
const& arr)
121 bool_t<Builder> nonzero_found =
false;
122 for (
size_t i = arr.size() - 1; i != (
size_t)-1; i--) {
123 bool_t<Builder> is_non_zero = arr[i] != 0;
124 nonzero_found |= is_non_zero;
126 return !nonzero_found;
133template <
typename Builder,
size_t size_1,
size_t size_2>
144 bool_t<Builder> hit_s_zero =
false;
145 bool_t<Builder> not_hit_s_zero =
true;
147 for (
size_t i = 0; i < source.max_size(); ++i) {
151 auto is_s_zero = s.is_zero();
152 hit_s_zero.must_imply(is_s_zero,
153 "Once we've hit the first source zero, there must only be zeros thereafter!");
154 hit_s_zero |= is_s_zero;
155 not_hit_s_zero = !hit_s_zero;
159 for (
size_t j = i; j < target.max_size(); ++j) {
163 bool_t<Builder> at_next_target_index = j_ct == next_target_index;
170 next_target_index += not_hit_s_zero;
172 next_target_index.assert_not_equal(overflow_capacity,
"push_array_to_array target array capacity exceeded");
Definition: widget.bench.cpp:13