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
self
to reserve space for a total ofvertexCount
vertices.Default Implementation
Hints
self
to reserve space for a total ofvertexCount
vertices.Declaration
Swift
mutating func reserveCapacity(vertexCount: Int)
-
Adds an edge from
source
todestination
into the graph.Precondition
if parallel edges are disallowed, there must not exist an edge fromsource
todestination
already 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
u
andv
are vertices inself
.Complexity
worst case O(|E|).Declaration
Swift
@discardableResult mutating func removeEdge(from u: VertexId, to v: VertexId) -> Bool
Return Value
true if one or more edges were removed; false otherwise.
-
Removes the edge
edge
from the graph.Precondition
edge
is a validEdgeId
fromself
.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
vertex
identified 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
vertex
from the graph.Precondition
vertex
is a validVertexId
forself
.Complexity
O(|E| + |V|)Declaration
Swift
mutating func remove(_ vertex: VertexId)
-
init(_:
Extension methodvertexMapping: ) Initializes
self
as 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
self
as 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
self
as 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