Directed graph supporting efficient cycle detection.
Construct a directed graph with a fixed number of vertices.
The graph stores a fixed number of vertices identified by integers in the range [1, vertices].
Edges are represented internally using a dense adjacency structure together with per-vertex occupancy counters. This approach avoids repeated allocations and is well suited to the relatively small dependency graphs encountered by fpx.
Initializes a new directed graph.
Constructor
| [in] | vertices | Number of vertices in the graph. |
Allocates the internal adjacency structures and initializes the graph without any edges.
| [in] | vertices | Number of vertices. |
| procedure, pass, public add_edge | ( | class(digraph), intent(inout) | this, |
| integer, intent(in) | source, | ||
| integer, intent(in) | destination, | ||
| logical, intent(out), optional | overflow ) |
Add a directed edge to the graph.
Inserts an edge from source to destination. If either vertex lies outside the valid range, the request is ignored.
| [in,out] | this | Graph instance. |
| [in] | source | Source vertex (1-based). |
| [in] | destination | Destination vertex (1-based). |
| [out] | overflow | Optional flag indicating whether the insertion position was already occupied. |
| procedure, pass, public is_circular | ( | class(digraph), intent(in) | this, |
| integer, intent(in) | start_vertex ) |
Determine whether a cycle is reachable from a vertex.
Performs a depth-first traversal starting from start_vertex and detects back edges using a recursion stack.
| [in] | this | Graph instance. |
| [in] | start_vertex | Vertex from which the search begins. |