|
SILICON
|
Runtime-only graph of Circuit-to-Circuit instantiation dependencies. More...
#include <circuitDependencyGraph.hpp>
Classes | |
| struct | VertexProperty |
| Per-vertex payload holding the document's project-relative path. More... | |
Public Types | |
| using | DocumentPathList = std::vector<std::string> |
| List of project-relative document paths. | |
Public Member Functions | |
| CircuitDependencyGraph ()=default | |
| CircuitDependencyGraph (const CircuitDependencyGraph &)=default | |
| CircuitDependencyGraph & | operator= (const CircuitDependencyGraph &)=default |
| CircuitDependencyGraph (CircuitDependencyGraph &&) noexcept=default | |
| CircuitDependencyGraph & | operator= (CircuitDependencyGraph &&) noexcept=default |
| void | clear () |
| Removes every vertex and edge, returning the graph to an empty state. | |
| void | addDocument (std::string_view documentPath) |
| Ensures a document vertex exists, creating it if necessary. | |
| void | removeDocument (std::string_view documentPath) |
| Removes an unreferenced document atomically. | |
| void | validateDocumentRemoval (std::string_view documentPath) const |
| void | rebuildFromProject (const std::vector< Document > &documents) |
| Rebuilds the graph from a full project description. | |
| void | replaceDocumentDependencies (std::string_view documentPath, std::string_view contents) |
| Replaces the dependency edges of a single document atomically. | |
| void | validateDocumentDependencies (std::string_view documentPath, std::string_view contents) const |
| bool | wouldIntroduceCycle (std::string_view documentPath, std::string_view contents) const |
| Tests whether rewiring a document's dependencies would create a cycle. | |
| DocumentPathList | dependentsOf (std::string_view subcircuitPath) const |
| Returns the sorted list of documents that depend on a subcircuit. | |
| bool | containsDocument (std::string_view documentPath) const |
| Checks whether a document vertex is present in the graph. | |
Private Types | |
| enum class | VisitState { Unvisited , Visiting , Visited } |
| DFS visit marker used while reconstructing a dependency cycle. More... | |
| using | Graph |
| Boost graph type: set out-edges, vector vertices, directed. | |
| using | Vertex = boost::graph_traits<Graph>::vertex_descriptor |
| Boost vertex descriptor (an integer index under vecS). | |
| using | PathToVertex |
| O(1) index mapping a document path to its graph vertex. | |
Private Member Functions | |
| std::optional< Vertex > | findVertex (std::string_view documentPath) const |
| CircuitDependencyGraph | withDocumentDependencies (std::string_view documentPath, std::string_view contents) const |
| void | replaceDependencyEdges (std::string_view documentPath, std::string_view contents) |
| std::vector< std::string > | findCycleTrace () const |
| Finds one recursive dependency cycle and returns it as ordered slugs. | |
| std::vector< std::string > | findCycleTraceFrom (Vertex vertex, std::vector< VisitState > &states, std::vector< Vertex > &path) const |
| DFS step used by findCycleTrace. | |
| std::vector< std::string > | cycleTraceEndingAt (Vertex repeated, const std::vector< Vertex > &path) const |
Builds a slug trace when DFS reaches a vertex already in path. | |
| void | throwIfCyclic () const |
| Throws a runtime error with a recursion trace if the graph is cyclic. | |
| Vertex | ensureVertex (std::string_view documentPath) |
| Ensures a document vertex exists in this graph (O(1)). | |
| void | rebuildPathIndex () |
| Rebuilds pathToVertex from the current graph. | |
| void | validateAcyclic () const |
| Verifies the graph is acyclic. | |
Private Attributes | |
| Graph | graph |
| The dependency graph itself. | |
| PathToVertex | pathToVertex |
| Path-to-vertex index kept in sync with graph. | |
Runtime-only graph of Circuit-to-Circuit instantiation dependencies.
Vertices are project-relative Circuit document paths such as circuits/main.json and circuits/adder.json. Edges point from a document to the reusable Circuit document it instantiates. Non-diagram documents are outside this deliberately narrow model. The graph is derived from persisted Circuit JSON and is never serialized into project archives.
The graph uses boost::vecS for its vertex container, which means vertex descriptors are integer indices. As a consequence, removing a vertex reindexes every subsequent vertex, so the pathToVertex index must be rebuilt after a removal. Path lookup remains average O(1) thanks to the std::unordered_map index. Public mutations use project-sized candidate copies for strong exception safety; removal additionally incurs an O(V) path-index rebuild.
Definition at line 50 of file circuitDependencyGraph.hpp.
| using DocumentPathList = std::vector<std::string> |
List of project-relative document paths.
Definition at line 59 of file circuitDependencyGraph.hpp.
|
private |
Boost graph type: set out-edges, vector vertices, directed.
Definition at line 165 of file circuitDependencyGraph.hpp.
|
private |
O(1) index mapping a document path to its graph vertex.
Definition at line 174 of file circuitDependencyGraph.hpp.
Boost vertex descriptor (an integer index under vecS).
Definition at line 168 of file circuitDependencyGraph.hpp.
|
strongprivate |
DFS visit marker used while reconstructing a dependency cycle.
| Enumerator | |
|---|---|
| Unvisited | |
| Visiting | |
| Visited | |
Definition at line 171 of file circuitDependencyGraph.hpp.
|
default |
|
default |
|
defaultnoexcept |
| void addDocument | ( | std::string_view | documentPath | ) |
Ensures a document vertex exists, creating it if necessary.
| documentPath | Project-relative path of the document to register. |
Definition at line 147 of file circuitDependencyGraph.cpp.
| void clear | ( | ) |
Removes every vertex and edge, returning the graph to an empty state.
Definition at line 141 of file circuitDependencyGraph.cpp.
|
nodiscard |
Checks whether a document vertex is present in the graph.
| documentPath | Project-relative path of the document to look up. |
Definition at line 257 of file circuitDependencyGraph.cpp.
|
nodiscardprivate |
Builds a slug trace when DFS reaches a vertex already in path.
| repeated | Vertex that closes the cycle. |
| path | Current DFS recursion path containing repeated. |
repeated through the current path, with repeated appended again at the end. Definition at line 348 of file circuitDependencyGraph.cpp.
|
nodiscard |
Returns the sorted list of documents that depend on a subcircuit.
| subcircuitPath | Project-relative path of the subcircuit document. |
Definition at line 241 of file circuitDependencyGraph.cpp.
|
nodiscardprivate |
Ensures a document vertex exists in this graph (O(1)).
| documentPath | Project-relative path of the document. |
Definition at line 365 of file circuitDependencyGraph.cpp.
|
nodiscardprivate |
Finds one recursive dependency cycle and returns it as ordered slugs.
The repeated slug is appended at the end of the trace, e.g. [cpu, alu, cpu]. Returns an empty vector when the graph is acyclic.
Definition at line 307 of file circuitDependencyGraph.cpp.
|
nodiscardprivate |
DFS step used by findCycleTrace.
| vertex | Vertex currently being visited. |
| states | Per-vertex DFS state, indexed by vertex descriptor. |
| path | Current recursion path from the DFS root to vertex. |
Definition at line 323 of file circuitDependencyGraph.cpp.
|
nodiscardprivate |
Definition at line 263 of file circuitDependencyGraph.cpp.
|
defaultnoexcept |
|
default |
| void rebuildFromProject | ( | const std::vector< Document > & | documents | ) |
Rebuilds the graph from a full project description.
All graphical documents are first registered as vertices and then wired with their dependency edges. The resulting graph must be acyclic; if it is not, a std::runtime_error is thrown and the graph is left unchanged.
| documents | The project's ordered documents. Non-graphical documents are ignored. |
| std::runtime_error | If the described dependencies form a cycle. |
Definition at line 189 of file circuitDependencyGraph.cpp.
|
private |
Rebuilds pathToVertex from the current graph.
Required after remove_vertex because vecS reindexes descriptors.
Definition at line 377 of file circuitDependencyGraph.cpp.
| void removeDocument | ( | std::string_view | documentPath | ) |
Removes an unreferenced document atomically.
If documentPath is not present in the graph this call is a no-op. If any document depends on it, removal is rejected and the graph is unchanged. Removing a vertex reindexes the remaining vertices (due to vecS), so the internal path index is rebuilt afterwards.
| documentPath | Project-relative path of the document to remove. |
Definition at line 161 of file circuitDependencyGraph.cpp.
|
private |
Definition at line 281 of file circuitDependencyGraph.cpp.
| void replaceDocumentDependencies | ( | std::string_view | documentPath, |
| std::string_view | contents ) |
Replaces the dependency edges of a single document atomically.
The new edges are computed against a private copy of the graph and only committed if every referenced subcircuit already exists and the resulting graph is acyclic; otherwise, a std::runtime_error is thrown and the graph is left unchanged.
| documentPath | Project-relative path of the document to update. |
| contents | Persisted Circuit document JSON to inspect. Both {"components":[...]} and the serialized scene form {"circuit":{"components":[...]}} are supported. A missing components member is accepted for legacy empty circuits; a present member must be an array. |
| std::runtime_error | If contents is malformed, references a missing subcircuit, or would create recursive dependencies. |
Definition at line 212 of file circuitDependencyGraph.cpp.
|
private |
Throws a runtime error with a recursion trace if the graph is cyclic.
Definition at line 392 of file circuitDependencyGraph.cpp.
|
private |
Verifies the graph is acyclic.
| boost::not_a_dag | If the graph contains a cycle. |
Definition at line 385 of file circuitDependencyGraph.cpp.
| void validateDocumentDependencies | ( | std::string_view | documentPath, |
| std::string_view | contents ) const |
Validates a candidate dependency update without mutating the graph. Missing documents, malformed references, and recursion retain distinct errors.
Definition at line 220 of file circuitDependencyGraph.cpp.
| void validateDocumentRemoval | ( | std::string_view | documentPath | ) | const |
Validates that a document can be removed without losing a source reference.
Definition at line 177 of file circuitDependencyGraph.cpp.
|
nodiscardprivate |
Definition at line 273 of file circuitDependencyGraph.cpp.
|
nodiscard |
Tests whether rewiring a document's dependencies would create a cycle.
Operates on a private copy of the graph, so it has no side effects.
| documentPath | Project-relative path of the document to test. |
| contents | Persisted Circuit document JSON to inspect. |
Definition at line 227 of file circuitDependencyGraph.cpp.
|
private |
The dependency graph itself.
Definition at line 179 of file circuitDependencyGraph.hpp.
|
private |
Path-to-vertex index kept in sync with graph.
Definition at line 181 of file circuitDependencyGraph.hpp.