DirectedAMatrix
final public class DirectedAMatrix<Vertex: Hashable>: AdjacencyMatrix<Vertex>,
DirectedGraph
Adjacency matrices for directed graphs.
-
Undocumented
Declaration
Swift
final public class DirectedAMatrix<Vertex: Hashable>: AdjacencyMatrix<Vertex>, DirectedGraph
-
An array of all the edges in the graph, represented as tuples of vertices.
The first vertex in each tuple is the source of the edge, and the second is the destination.
Complexity
O(V²)Declaration
Swift
public var edges: [(Vertex, Vertex)]
-
Returns whether there is an edge from one vertex to another in the graph.
Throws
GraphError.VertexNotPresent
if either vertex is not in the graph.Complexity
O(1)
Declaration
Swift
public func edgeExists(from: Vertex, to: Vertex) throws -> Bool
Parameters
from
The vertex to check from.
to
The destination vertex.
Return Value
true
if the edge exists;false
otherwise. -
Creates an array of all vertices reachable in one step from a vertex.
Throws
GraphError.VertexNotPresent
ifvertex
is not in the graph.Complexity
O(V)
Declaration
Swift
public func neighbors(vertex: Vertex) throws -> [Vertex]
Parameters
vertex
The vertex whose neighbors to retrieve.
Return Value
An array of all vertices with edges from
vertex
to them, in no particular order, and not includingvertex
unless there is a loop. -
Adds a new edge from one edge to another.
Changes the graph in-place to add the edge. The new edge will go from
from
toto
.Throws
GraphError.VertexNotPresent
if either vertex is not in the graph.Complexity
O(1)
Declaration
Swift
public func addEdge(from: Vertex, to: Vertex) throws
Parameters
from
The ‘source’ of the edge.
to
The ‘destination’ of the edge.
-
Removes an edge from one vertex to another.
Throws
GraphError.EdgeNotPresent
if the edge to be removed is not in the graph.Complexity
O(1)
Declaration
Swift
public func removeEdge(from: Vertex, to: Vertex) throws
Parameters
from
The ‘source’ of the edge.
to
The ‘destination’ of the edge.