UndirectedAMatrix
final public class UndirectedAMatrix<Vertex: Hashable>: AdjacencyMatrix<Vertex>,
UndirectedGraph
Adjacency matrices for undirected graphs.
-
Undocumented
Declaration
Swift
final public class UndirectedAMatrix<Vertex: Hashable>: AdjacencyMatrix<Vertex>, UndirectedGraph
-
An array of all the edges in the graph, represented as tuples of vertices.
Complexity
O(V²)Declaration
Swift
public var edges: [(Vertex, Vertex)]
-
Returns whether there is an edge between two vertices 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 adjacent to 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 between two vertices.
Changes the graph in-place to add the edge. This operation is symmetric; flipping the arguments makes no difference in the result.
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
One vertex on the edge.
to
The other vertex on the edge.
-
Removes an edge between two vertices.
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
One vertex on the edge.
to
The other vertex on the edge.