Graph

extension Graph where E == DependencyEdge

Adjust SwiftGraph‘s functions to accept edges of type DependencyEdge

Available where E == DependencyEdge

  • Initialize an UnweightedGraph consisting of path.

    The resulting graph has the vertices in path and an edge between each pair of consecutive vertices in path.

    If path is an empty array, the resulting graph is the empty graph. If path is an array with a single vertex, the resulting graph has that vertex and no edges.

    Note

    THIS FUNCTION IS CURRENTLY NOT REWORKED FOR DEPENDENCY GARPHS

    Declaration

    Swift

    public static func withPath(_ path: [(V, [EdgeRole])], directed: Bool = false) -> Self

    Parameters

    path

    An array of vertices representing a path.

    directed

    If false, undirected edges are created. If true, edges are directed from vertex i to vertex i+1 in path. Default is false.

  • Initialize an UnweightedGraph consisting of cycle.

    The resulting graph has the vertices in cycle and an edge between each pair of consecutive vertices in cycle, plus an edge between the last and the first vertices.

    If cycle is an empty array, the resulting graph is the empty graph. If cycle is an array with a single vertex, the resulting graph has the vertex and a single edge to itself if directed is true. If directed is false the resulting graph has the vertex and two edges to itself.

    Note

    THIS FUNCTION IS CURRENTLY NOT REWORKED FOR DEPENDENCY GARPHS

    Declaration

    Swift

    public static func withCycle(_ cycle: [(V, [EdgeRole])], directed: Bool = false) -> Self

    Parameters

    cycle

    An array of vertices representing a cycle.

    directed

    If false, undirected edges are created. If true, edges are directed from vertex i to vertex i+1 in cycle. Default is false.

  • This is a convenience method that adds an unweighted edge.

    Declaration

    Swift

    public func addEdge(fromIndex: Int, toIndex: Int, directed: Bool = false, role: [EdgeRole])

    Parameters

    from

    The starting vertex’s index.

    to

    The ending vertex’s index.

    directed

    Is the edge directed? (default false)

  • This is a convenience method that adds an unweighted, undirected edge between the first occurence of two vertices. It takes O(n) time.

    Declaration

    Swift

    public func addEdge(from: V, to: V, directed: Bool = false, role: [EdgeRole])

    Parameters

    from

    The starting vertex.

    to

    The ending vertex.

    directed

    Is the edge directed? (default false)

  • Check whether there is an edge from one vertex to another vertex.

    Declaration

    Swift

    public func edgeExists(fromIndex: Int, toIndex: Int, role: [EdgeRole]) -> Bool

    Parameters

    from

    The index of the starting vertex of the edge.

    to

    The index of the ending vertex of the edge.

    Return Value

    True if there is an edge from the starting vertex to the ending vertex.

  • Check whether there is an edge from one vertex to another vertex.

    Note this will look at the first occurence of each vertex. Also returns false if either of the supplied vertices cannot be found in the graph.

    Declaration

    Swift

    public func edgeExists(from: V, to: V, role: [EdgeRole]) -> Bool

    Parameters

    from

    The starting vertex of the edge.

    to

    The ending vertex of the edge.

    Return Value

    True if there is an edge from the starting vertex to the ending vertex.