2#include "barretenberg/crypto/pedersen_commitment/pedersen.hpp"
3#include "barretenberg/serialize/msgpack.hpp"
18 MSGPACK_FIELDS(value, nextIndex, nextValue);
21 std::ostream& operator<<(std::ostream& os)
23 os <<
"value = " << value <<
"\nnextIdx = " << nextIndex <<
"\nnextVal = " << nextValue;
27 barretenberg::fr hash()
const {
return stdlib::merkle_tree::hash_native({ value, nextIndex, nextValue }); }
75 barretenberg::fr hash()
const {
return data.has_value() ? data.value().hash() : barretenberg::fr::zero(); }
86 std::optional<nullifier_leaf> data;
89inline std::pair<size_t, bool> find_closest_leaf(std::vector<WrappedNullifierLeaf>
const& leaves_,
fr const& new_value)
91 std::vector<uint256_t> diff;
92 bool repeated =
false;
95 for (
size_t i = 0; i < leaves_.size(); i++) {
97 if (!leaves_[i].has_value()) {
98 diff.push_back(new_value_);
102 auto leaf_value_ =
uint256_t(leaves_[i].unwrap().value);
103 if (leaf_value_ > new_value_) {
104 diff.push_back(leaf_value_);
105 }
else if (leaf_value_ == new_value_) {
107 return std::make_pair(i, repeated);
109 diff.push_back(new_value_ - leaf_value_);
112 auto it = std::min_element(diff.begin(), diff.end());
113 return std::make_pair(
static_cast<size_t>(it - diff.begin()), repeated);
Definition: uint256.hpp:25
Wrapper for the Nullifier leaf class that allows for 0 values.
Definition: nullifier_leaf.hpp:34
static WrappedNullifierLeaf zero()
Generate a zero leaf (call the constructor with no arguments)
Definition: nullifier_leaf.hpp:82
nullifier_leaf unwrap() const
Return the wrapped nullifier_leaf object.
Definition: nullifier_leaf.hpp:61
bool has_value() const
Pass through the underlying std::optional method.
Definition: nullifier_leaf.hpp:54
void set(nullifier_leaf value)
Set the wrapped nullifier_leaf object value.
Definition: nullifier_leaf.hpp:68
barretenberg::fr hash() const
Return the hash of the wrapped object, other return the zero hash of 0.
Definition: nullifier_leaf.hpp:75
constexpr_utils defines some helper methods that perform some stl-equivalent operations but in a cons...
Definition: constexpr_utils.hpp:16
Definition: widget.bench.cpp:13
Definition: nullifier_leaf.hpp:12