Skip to main content

RuleDependencyGraph

Struct RuleDependencyGraph 

Source
pub struct RuleDependencyGraph { /* private fields */ }
Expand description

Directed graph capturing dependencies between rules and predicates.

Implementations§

Source§

impl RuleDependencyGraph

Source

pub fn new() -> Self

Create an empty graph.

Source

pub fn add_node(&mut self, node: DepNode)

Insert a node (idempotent).

Source

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.

Source

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:

  1. Adds Predicate(p.name) as a node.
  2. Creates a synthetic Rule("<p>_rule") that defines p.
  3. Adds a Defines edge from the rule node to the predicate node.
  4. For each argument domain d of p: adds Predicate(d) and a Positive edge from the rule to that domain predicate (modelling that evaluating p requires its domain to be populated).
Source

pub fn nodes(&self) -> &HashSet<DepNode>

All nodes in the graph.

Source

pub fn successors(&self, node: &DepNode) -> Vec<&DepNode>

Nodes that node has outgoing edges to (successors / dependencies).

Source

pub fn predecessors(&self, node: &DepNode) -> Vec<&DepNode>

Nodes that have outgoing edges pointing to node (predecessors).

Source

pub fn node_count(&self) -> usize

Total number of nodes.

Source

pub fn edge_count(&self) -> usize

Total number of directed edges.

Source

pub fn has_cycle(&self) -> bool

Returns true if the graph contains at least one directed cycle.

Source

pub fn find_cycle_nodes(&self) -> HashSet<&DepNode>

Return the set of nodes that participate in any cycle.

Source

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.

Source

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

Source

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.

Source

pub fn to_ascii(&self) -> String

Render as a human-readable ASCII adjacency list (for debugging).

Source

pub fn to_dot(&self) -> String

Render as Graphviz DOT format.

Trait Implementations§

Source§

impl Clone for RuleDependencyGraph

Source§

fn clone(&self) -> RuleDependencyGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RuleDependencyGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RuleDependencyGraph

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.