Skip to main content

DependencyGraph

Struct DependencyGraph 

Source
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>

Source

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);
Source

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.

Source

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.

Source

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.

Source

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);
Source

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.

Auto Trait Implementations§

§

impl<C, R> Freeze for DependencyGraph<C, R>

§

impl<C, R> RefUnwindSafe for DependencyGraph<C, R>

§

impl<C, R> Send for DependencyGraph<C, R>
where C: Send, R: Send,

§

impl<C, R> Sync for DependencyGraph<C, R>
where C: Sync, R: Sync,

§

impl<C, R> Unpin for DependencyGraph<C, R>
where C: Unpin, R: Unpin,

§

impl<C, R> UnsafeUnpin for DependencyGraph<C, R>

§

impl<C, R> UnwindSafe for DependencyGraph<C, R>
where C: UnwindSafe, R: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.