pub struct RuleDependencyGraph { /* private fields */ }Expand description
Directed graph capturing dependencies between rules and predicates.
Implementations§
Source§impl RuleDependencyGraph
impl RuleDependencyGraph
Sourcepub fn add_edge(&mut self, from: DepNode, to: DepNode, edge: DepEdge)
pub fn add_edge(&mut self, from: DepNode, to: DepNode, edge: DepEdge)
Insert a directed edge from from to to with edge type edge.
Both endpoints are automatically added as nodes.
Sourcepub fn from_symbol_table(table: &SymbolTable) -> Self
pub fn from_symbol_table(table: &SymbolTable) -> Self
Build a dependency graph from a SymbolTable.
Because SymbolTable stores predicates (not first-class rules with
heads/bodies), this method treats each predicate as both a defining
entity and a potential dependency. For every predicate p it:
- Adds
Predicate(p.name)as a node. - Creates a synthetic
Rule("<p>_rule")that definesp. - Adds a
Definesedge from the rule node to the predicate node. - For each argument domain
dofp: addsPredicate(d)and aPositiveedge from the rule to that domain predicate (modelling that evaluatingprequires its domain to be populated).
Sourcepub fn successors(&self, node: &DepNode) -> Vec<&DepNode>
pub fn successors(&self, node: &DepNode) -> Vec<&DepNode>
Nodes that node has outgoing edges to (successors / dependencies).
Sourcepub fn predecessors(&self, node: &DepNode) -> Vec<&DepNode>
pub fn predecessors(&self, node: &DepNode) -> Vec<&DepNode>
Nodes that have outgoing edges pointing to node (predecessors).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Total number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Total number of directed edges.
Sourcepub fn has_cycle(&self) -> bool
pub fn has_cycle(&self) -> bool
Returns true if the graph contains at least one directed cycle.
Sourcepub fn find_cycle_nodes(&self) -> HashSet<&DepNode>
pub fn find_cycle_nodes(&self) -> HashSet<&DepNode>
Return the set of nodes that participate in any cycle.
Sourcepub fn transitive_deps(&self, node: &DepNode) -> HashSet<DepNode>
pub fn transitive_deps(&self, node: &DepNode) -> HashSet<DepNode>
Compute all nodes reachable from node via BFS (all edge types).
The starting node itself is not included in the result.
Sourcepub fn strongly_connected_components(&self) -> Vec<Vec<DepNode>>
pub fn strongly_connected_components(&self) -> Vec<Vec<DepNode>>
Compute all strongly connected components.
Each SCC is returned as a Vec<DepNode>; SCCs are in reverse topological
order (i.e. the first SCC has no outgoing edges to later SCCs).
Sourcepub fn stratify(&self) -> Result<Vec<StratificationLayer>, StratificationError>
pub fn stratify(&self) -> Result<Vec<StratificationLayer>, StratificationError>
Compute Datalog stratification layers.
Returns Ok(layers) where layers are sorted by stratum index, or
Err(StratificationError::NegativeCycle{..}) when the graph is
unstratifiable.
Trait Implementations§
Source§impl Clone for RuleDependencyGraph
impl Clone for RuleDependencyGraph
Source§fn clone(&self) -> RuleDependencyGraph
fn clone(&self) -> RuleDependencyGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more