|
| 1 | +#include "circuit_constructor_base.hpp" |
| 2 | + |
| 3 | +namespace waffle { |
| 4 | + |
| 5 | +/** |
| 6 | + * Join variable class b to variable class a. |
| 7 | + * |
| 8 | + * @param a_variable_idx Index of a variable in class a. |
| 9 | + * @param b_variable_idx Index of a variable in class b. |
| 10 | + * @param msg Class tag. |
| 11 | + * */ |
| 12 | +void CircuitConstructorBase::assert_equal(const uint32_t a_variable_idx, |
| 13 | + const uint32_t b_variable_idx, |
| 14 | + std::string const& msg) |
| 15 | +{ |
| 16 | + assert_valid_variables({ a_variable_idx, b_variable_idx }); |
| 17 | + bool values_equal = (get_variable(a_variable_idx) == get_variable(b_variable_idx)); |
| 18 | + if (!values_equal && !failed()) { |
| 19 | + failure(msg); |
| 20 | + } |
| 21 | + uint32_t a_real_idx = real_variable_index[a_variable_idx]; |
| 22 | + uint32_t b_real_idx = real_variable_index[b_variable_idx]; |
| 23 | + // If a==b is already enforced, exit method |
| 24 | + if (a_real_idx == b_real_idx) |
| 25 | + return; |
| 26 | + // Otherwise update the real_idx of b-chain members to that of a |
| 27 | + |
| 28 | + auto b_start_idx = get_first_variable_in_class(b_variable_idx); |
| 29 | + update_real_variable_indices(b_start_idx, a_real_idx); |
| 30 | + // Now merge equivalence classes of a and b by tying last (= real) element of b-chain to first element of a-chain |
| 31 | + auto a_start_idx = get_first_variable_in_class(a_variable_idx); |
| 32 | + next_var_index[b_real_idx] = a_start_idx; |
| 33 | + prev_var_index[a_start_idx] = b_real_idx; |
| 34 | + bool no_tag_clash = (real_variable_tags[a_real_idx] == DUMMY_TAG || real_variable_tags[b_real_idx] == DUMMY_TAG || |
| 35 | + real_variable_tags[a_real_idx] == real_variable_tags[b_real_idx]); |
| 36 | + if (!no_tag_clash && !failed()) { |
| 37 | + failure(msg); |
| 38 | + } |
| 39 | + if (real_variable_tags[a_real_idx] == DUMMY_TAG) |
| 40 | + real_variable_tags[a_real_idx] = real_variable_tags[b_real_idx]; |
| 41 | +} |
| 42 | + |
| 43 | +} // namespace waffle |
0 commit comments