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 of vertexCount vertices.

    Default Implementation

    Hints self to reserve space for a total of vertexCount vertices.

    Declaration

    Swift

    mutating func reserveCapacity(vertexCount: Int)
  • Adds an edge from source to destination into the graph.

    Precondition

    if parallel edges are disallowed, there must not exist an edge from source to destination already present in self.

    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 and v are vertices in self.

    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 valid EdgeId from self.

    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 by shouldBeRemoved.

    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 valid VertexId for self.

    Complexity

    O(|E| + |V|)

    Declaration

    Swift

    mutating func remove(_ vertex: VertexId)

Available where Self: DefaultInitializable

Available where Self: DefaultInitializable, VertexId == Int