pub struct DependencyGraph<C, R> { /* private fields */ }Expand description
An owning graph of cell identities, method dependencies, and ordered guards.
Every edge connects registered cells. Relationship keys provide provenance, not runtime relationships; callers validate relationship structure separately. An input that also occurs in a method’s outputs contributes no outgoing edges. Repeated edges are retained, and guard insertion order sets diagnostic priority.
§Examples
See the module example.
Implementations§
Source§impl<C: Copy + Eq + Hash, R: Copy + Eq + Hash> DependencyGraph<C, R>
impl<C: Copy + Eq + Hash, R: Copy + Eq + Hash> DependencyGraph<C, R>
Sourcepub fn new(cells: impl IntoIterator<Item = C>) -> Self
pub fn new(cells: impl IntoIterator<Item = C>) -> Self
Creates a graph owning the supplied cell identities without dependencies.
Repeated keys identify the same cell; first occurrence determines node order.
- Complexity: Expected O(n) time and O(V) space for n supplied keys and V distinct cells, excluding key hashing and equality costs.
§Examples
use adam_rs::dependency::DependencyGraph;
let graph = DependencyGraph::<_, ()>::new([0, 1]);
assert_eq!(graph.analyze().unwrap().guard_depth(1), 0);Sourcepub fn add_method(&mut self, relationship: R, inputs: &[C], outputs: &[C])
pub fn add_method(&mut self, relationship: R, inputs: &[C], outputs: &[C])
Adds one authored method direction with relationship provenance.
Each input outside the output set contributes an edge to every output.
Empty inputs contribute no edges, as required for constant producers.
This operation records dependencies without validating relationship groups;
check_relationship_edges
remains the ordinary relationship validator.
- Precondition: Every input and output belongs to this graph.
- Complexity: Expected amortized O(I + O + E) time and O(O) temporary space for I inputs, O outputs, and E added edges, excluding key operation costs. Stores E additional edges.
§Examples
See the module example.
Sourcepub fn add_guard(&mut self, input: C, governed: C)
pub fn add_guard(&mut self, input: C, governed: C)
Adds a guard dependency from input to the cell it governs.
- Precondition: Both keys belong to this graph.
- Complexity: Expected amortized O(1) time, excluding key operation costs.
§Examples
See the module example.
Sourcepub fn add_dependency(&mut self, input: C, governed: C, hop: DependencyHop<R>)
pub fn add_dependency(&mut self, input: C, governed: C, hop: DependencyHop<R>)
Adds an already resolved dependency, including an ordinary self-edge.
Unlike Self::add_method, this operation does not apply read/write
overlap exclusion: callers have already resolved method semantics.
- Precondition: Both keys belong to this graph.
- Complexity: Expected amortized O(1), excluding key operation costs.
§Examples
See Self::project.
Sourcepub fn project(&self, boundaries: &[C]) -> DependencyProjection<C, R>
pub fn project(&self, boundaries: &[C]) -> DependencyProjection<C, R>
Projects both kinds of nonempty reachability onto the supplied boundary cells.
Retains one deterministic representative per pair and kind, using outgoing edge order to break traversal ties. Ordinary self-reachability requires a nonempty cycle; an isolated boundary contributes no path.
- Precondition: Every boundary belongs to this graph.
- Complexity: Expected O(B(V + E) + B²) time and O(BV + B²) result and auxiliary space for B supplied boundaries, V cells and E stored edges, excluding key operation costs. Shared prefixes are not expanded.
§Examples
use adam_rs::dependency::{DependencyGraph, DependencyHop};
let mut graph = DependencyGraph::new([0, 1, 2]);
graph.add_dependency(0, 1, DependencyHop::Method("copy"));
graph.add_guard(1, 2);
let projection = graph.project(&[0, 2]);
assert_eq!(projection.edges.len(), 1);
assert!(projection.edges[0].guarded);
assert_eq!(projection.steps[projection.edges[0].path].cell, 2);Sourcepub fn analyze(&self) -> Result<DependencyOrder<C>, DependencyPath<C, R>>
pub fn analyze(&self) -> Result<DependencyOrder<C>, DependencyPath<C, R>>
Validates guard independence and returns each cell’s guard depth.
Ordinary method-only cycles are legal. Equal-length diagnostic paths follow outgoing edge insertion order.
- Complexity: Expected O(V + E) time and auxiliary space for V cells and E stored edges, excluding key hashing and equality costs.
§Errors
Returns a shortest governed-cell-to-guard path for the first inserted guard that closes a cycle, including self-guards.
§Examples
See the module example.