DirectedAList
public class DirectedAList<Vertex: Hashable>: AdjacencyList<Vertex>,
DirectedGraph
Directed adjacency list. When using this class, source is different from destination vertex in an edge.
In other words, if u is in v’s neighbor array, v may not be in u’s unless the antiparallel edge exists in the graph.
-
Undocumented
Declaration
Swift
public class DirectedAList<Vertex: Hashable>: AdjacencyList<Vertex>, DirectedGraph
-
A computed array of all the edges in the graph, as tuples of vertices.
Source of the edge is the first element, so that (v, u) means v -> u.
Complexity
O(E)Declaration
Swift
public var edges: [(Vertex, Vertex)]
-
Adds a new edge from one vertex to another in the graph.
This is an asymmetric operation: order of arguments matters!
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 vertex of the desired edge
to
the destination vertex of the desired edge in other words, the edge (from -> to) will be added
-
Remove an edge from the graph.
Throws
GraphError.EdgeNotPresent
if the edge doesn’t exist in the graph,GraphError.VertexNotPresent
if either vertex doesn’t exist.Complexity
O(V), or O(D)
Declaration
Swift
public func removeEdge(from: Vertex, to: Vertex) throws
Parameters
from
the source vertex of the edge to remove.
to
the destination vertex of the edge to remove.