UniqueElementsGraph
An implementation Graph that ensures there are no pairs of equal vertices and no repeated edges.
-
Undocumented
Declaration
Swift
public var vertices: [V] -
Undocumented
Declaration
Swift
public var edges: [[E]] -
Undocumented
Declaration
Swift
public init() -
Init the Graph with vertices, but removes duplicates. O(n^2)
Declaration
Swift
required public init(vertices: [V]) -
Add a vertex to the graph if no equal vertex already belongs to the Graph. O(n)
Declaration
Swift
public func addVertex(_ v: V) -> IntParameters
vThe vertex to be added.
Return Value
The index where the vertex was added, or the index of the equal vertex already belonging to the graph.
-
Add an edge to the graph. Only allow the edge to be added once
Declaration
Swift
public func addEdge(_ e: E, directed: Bool = false)Parameters
eThe edge to add.
directedIf false, undirected edges are created. If true, a reversed edge is also created. Default is false.
-
Creates a new UniqueVerticesGraph that is the union of several UniqueVerticesGraphs.
This operation is commutative in the sense that g1 ∪ g2 has the same vertices and edges than g2 ∪ g1. However, the indices of the vertices are not guaranteed to be conserved.
This operation is O(k*n^2), where k is the number of graphs and n the number of vertices of the largest graph.
Declaration
Swift
static func unionOf(_ graphs: [UniqueElementsGraph]) -> UniqueElementsGraphParameters
graphsArray of graphs to build the union from.
-
Undocumented
Declaration
Swift
static func unionOf(_ graphs: UniqueElementsGraph...) -> UniqueElementsGraph
-
Initialize an UniqueElementsGraph 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.
Declaration
Swift
public static func withPath(_ path: [V], directed: Bool = false) -> UniqueElementsGraphParameters
pathAn array of vertices representing a path.
directedIf false, undirected edges are created. If true, edges are directed from vertex i to vertex i+1 in path. Default is false.
-
Initialize an UniqueElementsGraph 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 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 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.
Declaration
Swift
public static func withCycle(_ cycle: [V], directed: Bool = false) -> UniqueElementsGraphParameters
cycleAn array of vertices representing a cycle.
directedIf false, undirected edges are created. If true, edges are directed from vertex i to vertex i+1 in cycle. Default is false.
-
Undocumented
Declaration
Swift
public static func withPath(_ path: [V], directed: Bool = false) -> UniqueElementsGraph -
Undocumented
Declaration
Swift
public static func withCycle(_ cycle: [V], directed: Bool = false) -> UniqueElementsGraph
View on GitHub
UniqueElementsGraph Class Reference