BidirectionalAdjacencyList

public struct BidirectionalAdjacencyList<
  Vertex: DefaultInitializable,
  Edge: DefaultInitializable,
  RawId: BinaryInteger & IdIndexable
>: DirectedAdjacencyListProtocol, SearchDefaultsGraph where RawId.Stride: SignedInteger
extension BidirectionalAdjacencyList: BidirectionalGraph

A general purpose, bidirectional adjacency list graph.

BidirectionalAdjacencyList implements a bidirectional graph. Additionally, parallel edges are supported.

BidirectionalAdjacencyList also allows storing arbitrary additional data with each vertex and edge. If you select a zero-sized type (such as Empty), all overhead is optimized away by the Swift compiler.

Note: because tuples cannot yet conform to protocols, we have to use a separate type (Empty) instead of Void.

Operations that do not modify the graph structure occur in O(1) time. Additional operations that run in O(1) (amortized) time include: adding a new edge, and adding a new vertex. Operations that remove either vertices or edges invalidate existing VertexIds and EdgeIds. Adding new vertices or edges do not invalidate previously retrieved ids.

BidirectionalAdjacencyList is parameterized by the RawId which can be carefully tuned to save memory. A good default is Int32, unless you are trying to represent more than 2^32 vertices.

Incidence graph

SearchDefaultsGraph

Mutable graph operations

MutablePropertyGraph

  • Adds a new vertex with associated vertexProperty, returning its identifier.

    Complexity

    O(1) (amortized)

    Declaration

    Swift

    public mutating func addVertex(storing vertexProperty: Vertex) -> VertexId
  • Adds a new edge from source to destination and associated edgeProperty, returning its identifier.

    Complexity

    O(1) (amortized)

    Declaration

    Swift

    public mutating func addEdge(
      from source: VertexId, to destination: VertexId, storing edgeProperty: Edge
    ) -> EdgeId

BidirectionalAdjacencyList