formualizer_eval/engine/topo/
mod.rs

1//! Dynamic topological ordering utilities
2//!
3//! Exposes a Pearce–Kelly based fully-dynamic topological orderer. This module owns
4//! only ordering metadata; the dependency graph remains the source of truth for edges.
5
6pub mod pk;
7
8use crate::engine::graph::DependencyGraph;
9use crate::engine::vertex::VertexId;
10
11/// Adapter to expose the engine's dependency graph as a conceptual DAG view
12/// where edges go from precedent (dependency) -> dependent (formula).
13#[derive(Clone, Copy, Debug)]
14pub struct GraphAdapter<'a> {
15    pub g: &'a DependencyGraph,
16}
17
18impl<'a> GraphAdapter<'a> {
19    pub fn new(g: &'a DependencyGraph) -> Self {
20        Self { g }
21    }
22}
23
24impl pk::GraphView<VertexId> for GraphAdapter<'_> {
25    fn successors(&self, n: VertexId, out: &mut Vec<VertexId>) {
26        // Conceptual successors of a precedent are dependents in our storage
27        out.clear();
28        out.extend(self.g.get_dependents(n));
29    }
30
31    fn predecessors(&self, n: VertexId, out: &mut Vec<VertexId>) {
32        // Conceptual predecessors of a dependent are its dependencies in storage
33        out.clear();
34        out.extend(self.g.get_dependencies(n));
35    }
36
37    fn exists(&self, n: VertexId) -> bool {
38        self.g.vertex_exists(n)
39    }
40}