23 if (a_size != b_size) {
24 data[
"sizes"] = {a_size, b_size};
27 const int64_t size = std::max(a_size, b_size);
29 for (int64_t index = 0; index < size; ++index) {
30 auto write_value = [&](
const auto& attr) -> std::vector<T> {
31 if (index >= attr.reserved_size()) {
34 std::vector<T> r(attr.dimension());
35 auto v = attr.const_vector_attribute(index);
36 std::copy(v.begin(), v.end(), r.begin());
39 if constexpr (std::is_same_v<T, wmtk::Rational>) {
44 if (a_values.size() == 0) {
47 if (b_values.size() == 0) {
50 if (a_values != b_values) {
52 mydat[
"index"] = index;
53 mydat[
"values"] = {a_values, b_values};
61 const MerkleTreeInteriorNode& a,
62 const MerkleTreeInteriorNode& b,
63 bool detailed =
false)
66 auto a_child_hashables = a.child_hashables();
67 auto b_child_hashables = b.child_hashables();
68 for (
const auto& [name, a_hashable_ptr] : a_child_hashables) {
69 if (
auto it = b_child_hashables.find(name); it != b_child_hashables.end()) {
70 const auto& b_hashable_ptr = std::get<1>(*it);
71 auto cdiff_opt =
merkle_tree_diff(*a_hashable_ptr, *b_hashable_ptr, detailed =
true);
72 if (!cdiff_opt.has_value()) {
75 diff[name] = cdiff_opt.value();
94 for (
const auto& [name, a_hash] : a_child_hashes) {
96 if (b_child_hashes.find(name) != b_child_hashes.end()) {
97 size_t b_hash = b_child_hashes[name];
98 if (a_hash == b_hash) {
105 diff[name] = nlohmann::json::array({a_value, b_value});
109 for (
const auto& [name,
hash] : b_child_hashes) {
111 if (b_child_hashes.find(name) != b_child_hashes.end()) {
115 diff[name] = nlohmann::json::array({a_value, b_value});
124 auto try_cast = [&](
auto&& type) {
125 using T = std::decay_t<decltype(*type)>;
126 std::optional<std::array<const T*, 2>> ret;
127 auto a_ptr =
dynamic_cast<const T*
>(&a), b_ptr =
dynamic_cast<const T*
>(&b);
128 if (a_ptr !=
nullptr && b_ptr !=
nullptr) {
129 ret = std::array<const T*, 2>{{a_ptr, b_ptr}};
136 merkle_pair_opt.has_value()) {
137 const auto& m_pr = merkle_pair_opt.value();
138 const auto& m_a = *m_pr[0];
139 const auto& m_b = *m_pr[1];
142 for (
const auto& kv : cdiff.items()) {
143 diff[kv.key()] = kv.value();
147 auto try_attr = [&](
auto&& type) {
148 using T = std::decay_t<decltype(type)>;
151 attr_pair_opt.has_value()) {
152 const auto& a_pr = attr_pair_opt.value();
153 const auto& a_a = *a_pr[0];
154 const auto& a_b = *a_pr[1];
157 diff[
"details"] = attribute_detailed_data_diff(a_a, a_b);
This class stores data of type T in a vector.
int64_t dimension() const
The number of values for each index.
int64_t reserved_size() const
The total number of elements in a vector.
virtual std::map< std::string, size_t > child_hashes() const
virtual std::size_t hash() const
std::optional< nlohmann::json > merkle_tree_diff(const Hashable &a, const Hashable &b, bool detailed)