════════════════════════════════════════════════════════════════════════════════ TREE DIFF SHOWCASE - Demonstrating Current Limitations ════════════════════════════════════════════════════════════════════════════════

HASH SUPPORT CHECK Checking which SVG types have vtable.hash filled in:

String Hash: YES i32 Hash: YES bool Hash: YES --- Svg Hash: NO SvgElement Hash: NO SvgRect Hash: NO SvgCircle Hash: NO SvgGroup Hash: NO Vec Hash: NO

Conclusion: Custom structs/enums don't have Hash - we need structural hashing!

STRUCTURAL HASHING But with Peek::structural_hash, we can hash any Facet type:

svg1 (red rect) hash: e704ac169c8275a1 svg2 (clone) hash: e704ac169c8275a1 svg3 (blue rect) hash: 4e45605b6ceb322b

svg1 == svg2: YES (hashes match!) svg1 == svg3: NO (hashes differ!)

This showcase demonstrates how facet-diff currently handles tree mutations. The goal is to identify areas for improvement with Merkle-tree based diffing.

──────────────────────────────────────────────────────────────────────────────── SCENARIO: Deep Attribute Change Change a single attribute (fill: red → green) deep in a nested group. ────────────────────────────────────────────────────────────────────────────────

Diff output: { .. 2 unchanged fields children: [ Group { .. 1 unchanged field children: [ Rect { .. 4 unchanged fields fill: "red" → "green" }

    Circle (structurally equal)
    
  ]
}

] }

──────────────────────────────────────────────────────────────────────────────── SCENARIO: Swap Two Children Swap the order of rect and circle elements. Ideally shows as a reorder, not delete+insert. ────────────────────────────────────────────────────────────────────────────────

Diff output: { .. 2 unchanged fields children: [ - SvgElement::Rect(SvgRect { x: "10", y: "10", width: "30", height: "30", fill: "red", }) Circle (structurally equal)

+ SvgElement::Rect(SvgRect {
  x: "10",
  y: "10",
  width: "30",
  height: "30",
  fill: "red",
})

] }

──────────────────────────────────────────────────────────────────────────────── SCENARIO: Delete a Child Remove the middle element (circle) from a list of three elements. ────────────────────────────────────────────────────────────────────────────────

Diff output: { .. 2 unchanged fields children: [ - SvgElement::Rect(SvgRect { x: "10", y: "10", width: "30", height: "30", fill: "red", }) - SvgElement::Circle(SvgCircle { cx: "50", cy: "50", r: "15", fill: "green", }) Rect { fill: "blue" → "red" height: "20" → "30" width: "20" → "30" x: "70" → "10" y: "70" → "10" }

+ SvgElement::Rect(SvgRect {
  x: "70",
  y: "70",
  width: "20",
  height: "20",
  fill: "blue",
})

] }

──────────────────────────────────────────────────────────────────────────────── SCENARIO: Add a Child Insert a new circle element between two existing rect elements. ────────────────────────────────────────────────────────────────────────────────

Diff output: { .. 2 unchanged fields children: [ Rect (structurally equal)

+ SvgElement::Circle(SvgCircle {
  cx: "50",
  cy: "50",
  r: "15",
  fill: "green",
})
Rect (structurally equal)

] }

──────────────────────────────────────────────────────────────────────────────── SCENARIO: Move a Child Between Groups Move the circle from the 'left' group to the 'right' group. Ideally detected as a move. ────────────────────────────────────────────────────────────────────────────────

Diff output: { .. 2 unchanged fields children: [ Group { .. 1 unchanged field children: [ - SvgElement::Circle(SvgCircle { cx: "25", cy: "50", r: "20", fill: "red", }) ] }

Group {
  .. 1 unchanged field
  children: [
    Rect (structurally equal)
    
    + SvgElement::Circle(SvgCircle {
      cx: "25",
      cy: "50",
      r: "20",
      fill: "red",
    })
  ]
}

] }

──────────────────────────────────────────────────────────────────────────────── SCENARIO: Nested Group Modification Modify circle attributes (fill, r) three levels deep in nested groups. ────────────────────────────────────────────────────────────────────────────────

Diff output: { .. 2 unchanged fields children: [ Group { .. 1 unchanged field children: [ Group { .. 1 unchanged field children: [ Rect (structurally equal)

      ]
    }
    
    Group {
      .. 1 unchanged field
      children: [
        Circle {
          .. 2 unchanged fields
          fill: "blue" → "yellow"
          r: "30" → "40"
        }
        
      ]
    }
    
  ]
}

] }

════════════════════════════════════════════════════════════════════════════════ END OF SHOWCASE ════════════════════════════════════════════════════════════════════════════════