pub fn graph_diff(
graph1: &SqliteGraph,
graph2: &SqliteGraph,
) -> Result<GraphDiffResult, SqliteGraphError>Expand description
Computes structural graph diff between two snapshots.
Returns comprehensive delta information including nodes/edges added/removed and similarity metrics from Phase 54’s structural_similarity() function.
§Arguments
graph1- First graph (baseline, “before” snapshot)graph2- Second graph (comparison, “after” snapshot)
§Returns
GraphDiffResult containing:
nodes_added: Nodes present in graph2 but not in graph1nodes_removed: Nodes present in graph1 but not in graph2edges_added: Edges present in graph2 but not in graph1edges_removed: Edges present in graph1 but not in graph2similarity_score: Structural similarity (0.0 to 1.0)is_isomorphic: True if graphs are structurally identicalgraph_edit_distance: Simplified GED (1.0 - similarity)graph1_size: Number of nodes in graph1graph2_size: Number of nodes in graph2
§Example
ⓘ
use sqlitegraph::{algo::graph_diff, SqliteGraph};
let graph_v1 = SqliteGraph::open_in_memory()?;
let graph_v2 = SqliteGraph::open_in_memory()?;
// ... build graphs representing different versions ...
let diff = graph_diff(&graph_v1, &graph_v2)?;
if diff.has_breaking_changes() {
println!("WARNING: {} nodes removed", diff.nodes_removed.len());
} else if diff.is_safe() {
println!("Refactor looks safe (similarity: {:.2})", diff.similarity_score);
}
// See detailed changes
for &node_id in &diff.nodes_added {
println!("Added node: {}", node_id);
}§Use Cases
- Regression Detection: Compare test runs to identify what changed
- Refactor Validation: Verify optimization preserved structure
- Version Comparison: Track structural evolution across versions
- Impact Analysis: Identify affected regions by diffing before/after
§Complexity
Time: O(V + E) for delta computation + isomorphism check time Space: O(V + E) for storing delta sets