Loading...
Searching...
No Matches
digraph

Definition

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.

Examples

type(digraph) :: g
g = digraph(2)
call g%add_edge(1, 2)
print *, g%is_circular(1)

Constructors

Initializes a new directed graph.

Constructor

type(digraph) function digraph(integer vertices)
Parameters
[in]verticesNumber of vertices in the graph.
Returns
A newly constructed directed graph.

Remarks

  • Vertices are numbered from 1.
  • The number of vertices is fixed after construction.
  • Intended primarily for internal use by the macro expander.

Allocates the internal adjacency structures and initializes the graph without any edges.

Parameters
[in]verticesNumber of vertices.
Returns
Newly initialized graph.

Definition at line 115 of file graph.f90.


The documentation for this interface was generated from the following file:

Methods

◆ add_edge()

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.

Parameters
[in,out]thisGraph instance.
[in]sourceSource vertex (1-based).
[in]destinationDestination vertex (1-based).
[out]overflowOptional flag indicating whether the insertion position was already occupied.
Note
Duplicate edges are not explicitly filtered.

Definition at line 121 of file graph.f90.

◆ is_circular()

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.

Parameters
[in]thisGraph instance.
[in]start_vertexVertex from which the search begins.
Returns
.true. if a cycle exists in the reachable component; .false. otherwise.

Definition at line 122 of file graph.f90.

Constructor & Destructor Documentation

◆ graph_final()

final graph_final ( type(digraph), intent(inout) this)
final

Finalizer for the directed graph.

Releases all dynamically allocated storage associated with the graph when it leaves scope.

Definition at line 123 of file graph.f90.