pub struct DepGraph { /* private fields */ }Expand description
Dependency graph for incremental layout invalidation.
Tracks layout nodes and their dependencies. When a node’s input changes, the graph propagates dirtiness to all transitive dependents.
§Examples
use ftui_layout::dep_graph::{DepGraph, InputKind};
let mut graph = DepGraph::new();
// Create a simple parent → child dependency.
let parent = graph.add_node();
let child = graph.add_node();
graph.add_edge(child, parent).unwrap(); // child depends on parent
// Changing the parent dirties the child.
graph.mark_changed(parent, InputKind::Constraint, 42);
let dirty = graph.propagate();
assert!(dirty.contains(&parent));
assert!(dirty.contains(&child));Implementations§
Source§impl DepGraph
impl DepGraph
Sourcepub fn with_capacity(node_cap: usize, _edge_cap: usize) -> Self
pub fn with_capacity(node_cap: usize, _edge_cap: usize) -> Self
Create a graph with pre-allocated capacity.
Sourcepub fn add_node(&mut self) -> NodeId
pub fn add_node(&mut self) -> NodeId
Add a new node to the graph. Returns its stable identifier.
Sourcepub fn remove_node(&mut self, id: NodeId)
pub fn remove_node(&mut self, id: NodeId)
Remove a node, recycling its slot. Edges are lazily cleaned.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Total number of live nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Total number of edges (forward).
Sourcepub fn set_parent(&mut self, child: NodeId, parent: NodeId)
pub fn set_parent(&mut self, child: NodeId, parent: NodeId)
Set the parent of a node (structural tree relationship).
Sourcepub fn add_edge(&mut self, from: NodeId, to: NodeId) -> Result<(), CycleError>
pub fn add_edge(&mut self, from: NodeId, to: NodeId) -> Result<(), CycleError>
Add a dependency edge: from depends on to.
Returns Err(CycleError) if this would create a cycle.
Sourcepub fn mark_changed(&mut self, id: NodeId, kind: InputKind, new_hash: u64)
pub fn mark_changed(&mut self, id: NodeId, kind: InputKind, new_hash: u64)
Mark a node’s input as changed. The node and its transitive
dependents will be dirtied on the next propagate() call.
The new_hash is compared against the stored hash for the given
kind. If unchanged, the node is not dirtied (deduplication).
Sourcepub fn mark_dirty(&mut self, id: NodeId)
pub fn mark_dirty(&mut self, id: NodeId)
Force-mark a node as dirty without hash comparison.
Sourcepub fn propagate(&mut self) -> Vec<NodeId>
pub fn propagate(&mut self) -> Vec<NodeId>
Propagate dirtiness from pending dirty nodes to all transitive dependents via BFS on reverse edges.
Returns the complete dirty set in DFS pre-order (matching full layout traversal order) for deterministic recomputation.
Sourcepub fn constraint_hash(&self, id: NodeId) -> Option<u64>
pub fn constraint_hash(&self, id: NodeId) -> Option<u64>
Get the constraint hash for a node.
Sourcepub fn content_hash(&self, id: NodeId) -> Option<u64>
pub fn content_hash(&self, id: NodeId) -> Option<u64>
Get the content hash for a node.
Sourcepub fn style_hash(&self, id: NodeId) -> Option<u64>
pub fn style_hash(&self, id: NodeId) -> Option<u64>
Get the style hash for a node.
Sourcepub fn dirty_nodes(&self) -> impl Iterator<Item = NodeId> + '_
pub fn dirty_nodes(&self) -> impl Iterator<Item = NodeId> + '_
Iterate all live, dirty node IDs.
Sourcepub fn dirty_count(&self) -> usize
pub fn dirty_count(&self) -> usize
Count of currently dirty nodes.
Sourcepub fn dependencies(&self, id: NodeId) -> &[NodeId]
pub fn dependencies(&self, id: NodeId) -> &[NodeId]
Get forward dependencies for a node (what it depends on).
Sourcepub fn dependents(&self, id: NodeId) -> &[NodeId]
pub fn dependents(&self, id: NodeId) -> &[NodeId]
Get reverse dependencies for a node (what depends on it).
Sourcepub fn invalidate_all(&mut self)
pub fn invalidate_all(&mut self)
Invalidate all nodes (equivalent to full layout). Used as a fallback when incremental is not possible.