MutableGraph
public protocol MutableGraph : GraphProtocol
A MutableGraph can be changed via the addition and removal of edges and vertices.
In the documentation of complexity guarantees, |V| is the number of nodes, and |E| is the number of edges.
-
reserveCapacity(vertexCount:Default implementation) Hints
selfto reserve space for a total ofvertexCountvertices.Default Implementation
Hints
selfto reserve space for a total ofvertexCountvertices.Declaration
Swift
mutating func reserveCapacity(vertexCount: Int) -
Adds an edge from
sourcetodestinationinto the graph.Precondition
if parallel edges are disallowed, there must not exist an edge fromsourcetodestinationalready present inself.Complexity
either O(1) (amortized) or O(log(|E|/|V|)) if checking for parallel edges.Declaration
Swift
mutating func addEdge(from source: VertexId, to destination: VertexId) -> EdgeId -
Removes the edge (u, v) if present in
self.If the graph allows parallel edges, it removes all matching edges.
Precondition
uandvare vertices inself.Complexity
worst case O(|E|).Declaration
Swift
@discardableResult mutating func removeEdge(from u: VertexId, to v: VertexId) -> BoolReturn Value
true if one or more edges were removed; false otherwise.
-
Removes the edge
edgefrom the graph.Precondition
edgeis a validEdgeIdfromself.Declaration
Swift
mutating func remove(_ edge: EdgeId) -
Removes all edges identified by
shouldBeRemoved.Declaration
Swift
mutating func removeEdges(where shouldBeRemoved: (EdgeId, Self) -> Bool) -
Removes all out edges from
vertexidentified byshouldBeRemoved.Complexity
O(|E|)Declaration
Swift
mutating func removeEdges(from vertex: VertexId, where shouldBeRemoved: (EdgeId, Self) -> Bool) -
Adds a new vertex, returning its identifier.
Complexity
O(1) (amortized)Declaration
Swift
mutating func addVertex() -> VertexId -
Removes all edges from
vertex.Complexity
worst case O(|E| + |V|).Declaration
Swift
mutating func clear(vertex: VertexId) -
Removes
vertexfrom the graph.Precondition
vertexis a validVertexIdforself.Complexity
O(|E| + |V|)Declaration
Swift
mutating func remove(_ vertex: VertexId)
-
init(_:Extension methodvertexMapping: ) Initializes
selfas a copy of the incidences ofOther.Complexity
O(|V| + |E|)Declaration
Swift
public init< Other: IncidenceGraph & VertexListGraph, VertexMapping: ExternalPropertyMap >(_ other: Other, vertexMapping: inout VertexMapping) where VertexMapping.Graph == Other, VertexMapping.Key == Other.VertexId, VertexMapping.Value == VertexId -
init(_:Extension method) Initializes
selfas a copy of the incidences ofOther.Complexity
O(|V| + |E|)Declaration
Swift
public init<Other: IncidenceGraph & VertexListGraph & SearchDefaultsGraph>(_ other: Other) where Other.VertexId == VertexId
-
init(_:Extension method) Initializes
selfas a copy of the incidences ofOther.Complexity
O(|V| + |E|)Declaration
Swift
public init<Other: IncidenceGraph & VertexListGraph & SearchDefaultsGraph>(_ other: inout Other) where Other.VertexId == VertexId
View on GitHub
MutableGraph Protocol Reference