23#include <unordered_map>
26#include <boost/graph/adjacency_list.hpp>
119 std::string_view contents);
126 std::string_view contents) const;
139 std::string_view contents) const;
166 boost::adjacency_list<boost::setS, boost::vecS, boost::directedS, VertexProperty>;
168 using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
183 [[nodiscard]] std::optional<Vertex>
findVertex(std::string_view documentPath)
const;
187 std::string_view contents)
const;
208 [[nodiscard]] std::vector<std::string>
210 std::vector<Vertex>& path)
const;
220 [[nodiscard]] std::vector<std::string>
std::vector< std::string > DocumentPathList
List of project-relative document paths.
CircuitDependencyGraph & operator=(const CircuitDependencyGraph &)=default
void throwIfCyclic() const
Throws a runtime error with a recursion trace if the graph is cyclic.
void rebuildPathIndex()
Rebuilds pathToVertex from the current graph.
std::optional< Vertex > findVertex(std::string_view documentPath) const
std::unordered_map< std::string, Vertex, core::TransparentStringHash, core::TransparentStringEqual > PathToVertex
O(1) index mapping a document path to its graph vertex.
bool containsDocument(std::string_view documentPath) const
Checks whether a document vertex is present in the graph.
CircuitDependencyGraph(CircuitDependencyGraph &&) noexcept=default
CircuitDependencyGraph()=default
Graph graph
The dependency graph itself.
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.
boost::adjacency_list< boost::setS, boost::vecS, boost::directedS, VertexProperty > Graph
Boost graph type: set out-edges, vector vertices, directed.
bool wouldIntroduceCycle(std::string_view documentPath, std::string_view contents) const
Tests whether rewiring a document's dependencies would create a cycle.
CircuitDependencyGraph withDocumentDependencies(std::string_view documentPath, std::string_view contents) const
void removeDocument(std::string_view documentPath)
Removes an unreferenced document atomically.
void validateDocumentDependencies(std::string_view documentPath, std::string_view contents) const
VisitState
DFS visit marker used while reconstructing a dependency cycle.
DocumentPathList dependentsOf(std::string_view subcircuitPath) const
Returns the sorted list of documents that depend on a subcircuit.
void replaceDocumentDependencies(std::string_view documentPath, std::string_view contents)
Replaces the dependency edges of a single document atomically.
PathToVertex pathToVertex
Path-to-vertex index kept in sync with graph.
CircuitDependencyGraph(const CircuitDependencyGraph &)=default
void addDocument(std::string_view documentPath)
Ensures a document vertex exists, creating it if necessary.
void clear()
Removes every vertex and edge, returning the graph to an empty state.
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.
boost::graph_traits< Graph >::vertex_descriptor Vertex
Boost vertex descriptor (an integer index under vecS).
void rebuildFromProject(const std::vector< Document > &documents)
Rebuilds the graph from a full project description.
Vertex ensureVertex(std::string_view documentPath)
Ensures a document vertex exists in this graph (O(1)).
void validateAcyclic() const
Verifies the graph is acyclic.
void validateDocumentRemoval(std::string_view documentPath) const
std::vector< std::string > findCycleTraceFrom(Vertex vertex, std::vector< VisitState > &states, std::vector< Vertex > &path) const
DFS step used by findCycleTrace.
Transparent equality functor for string-like keys.
Transparent hash functor for string-like keys.
Per-vertex payload holding the document's project-relative path.