Skip to main content

DepGraph

Struct DepGraph 

Source
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

Source

pub fn new() -> Self

Create an empty dependency graph.

Source

pub fn with_capacity(node_cap: usize, _edge_cap: usize) -> Self

Create a graph with pre-allocated capacity.

Source

pub fn add_node(&mut self) -> NodeId

Add a new node to the graph. Returns its stable identifier.

Source

pub fn remove_node(&mut self, id: NodeId)

Remove a node, recycling its slot. Edges are lazily cleaned.

Source

pub fn node_count(&self) -> usize

Total number of live nodes.

Source

pub fn edge_count(&self) -> usize

Total number of edges (forward).

Source

pub fn set_parent(&mut self, child: NodeId, parent: NodeId)

Set the parent of a node (structural tree relationship).

Source

pub fn parent(&self, id: NodeId) -> Option<NodeId>

Get the parent of a node, if any.

Source

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.

Source

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).

Source

pub fn mark_dirty(&mut self, id: NodeId)

Force-mark a node as dirty without hash comparison.

Source

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.

Source

pub fn is_dirty(&self, id: NodeId) -> bool

Check if a node is currently dirty.

Source

pub fn clean(&mut self, id: NodeId)

Clean a single node (mark as not dirty).

Source

pub fn clean_all(&mut self)

Clean all nodes and advance the generation.

Source

pub fn constraint_hash(&self, id: NodeId) -> Option<u64>

Get the constraint hash for a node.

Source

pub fn content_hash(&self, id: NodeId) -> Option<u64>

Get the content hash for a node.

Source

pub fn style_hash(&self, id: NodeId) -> Option<u64>

Get the style hash for a node.

Source

pub fn dirty_nodes(&self) -> impl Iterator<Item = NodeId> + '_

Iterate all live, dirty node IDs.

Source

pub fn dirty_count(&self) -> usize

Count of currently dirty nodes.

Source

pub fn dependencies(&self, id: NodeId) -> &[NodeId]

Get forward dependencies for a node (what it depends on).

Source

pub fn dependents(&self, id: NodeId) -> &[NodeId]

Get reverse dependencies for a node (what depends on it).

Source

pub fn invalidate_all(&mut self)

Invalidate all nodes (equivalent to full layout). Used as a fallback when incremental is not possible.

Trait Implementations§

Source§

impl Default for DepGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.