GraphProtocol

public protocol GraphProtocol

Interface for graph-like tyes.

Associated Types

  • The type of nodes contained herein.

    Declaration

    Swift

    associatedtype Node : Hashable where Self.Node == Self.Edge.A
  • The type of edges contained herein.

    Declaration

    Swift

    associatedtype Edge : SymmetricPair, Hashable

Instance Properties

  • All of the nodes contained herein.

    Declaration

    Swift

    var nodes: Set<Node> { get set }
  • All of the edges contained herein.

    Declaration

    Swift

    var edges: Set<Edge> { get }

Instance Methods

  • remove(_:) Default implementation

    Removes edge from graph.

    Default Implementation

    Removes the given node and removes all edges that contain it.

    Declaration

    Swift

    mutating func remove(_ edge: Edge)
  • insert(_:) Extension method

    Inserts the given node without making any connections to other nodes contained herein.

    Declaration

    Swift

    @inlinable
    public mutating func insert(_ node: Node)
  • removeEdge(from:to:) Extension method

    Removes the edge from the given source to the given destination.

    Declaration

    Swift

    @inlinable
    public mutating func removeEdge(from source: Node, to destination: Node)
  • contains(_:) Extension method

    Declaration

    Swift

    @inlinable
    public func contains(_ node: Node) -> Bool

    Return Value

    true if the GraphProtocol-conforming type value contains the given node. Otherwise, false.

  • containsEdge(from:to:) Extension method

    Declaration

    Swift

    @inlinable
    public func containsEdge(from source: Node, to destination: Node) -> Bool

    Return Value

    true if this graph contains an edge between given source and destination. Otherwise, false.

  • contains(_:) Extension method

    Returns: true if the GraphProtocol-conforming type value contains the given edge. Otherwise, false.

    Declaration

    Swift

    @inlinable
    public func contains(_ edge: Edge) -> Bool
  • neighbors(of:in:) Extension method

    If nodes is empty, then any nodes contained herein are able to be included in the resultant set.

    Declaration

    Swift

    @inlinable
    public func neighbors(of source: Node, in nodes: Set<Node>? = nil) -> Set<Node>

    Return Value

    A set of nodes connected to the given source, in the given set of nodes.

  • edges(from:) Extension method

    Declaration

    Swift

    @inlinable
    public func edges(from source: Node) -> Set<Edge>

    Return Value

    A set of edges outgoing from the given source.

  • edges(to:) Extension method

    Declaration

    Swift

    @inlinable
    public func edges(to destination: Node) -> Set<Edge>

    Return Value

    A set of edges incident to the given destination.

  • breadthFirstSearch(from:to:) Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    public func breadthFirstSearch(from source: Node, to destination: Node? = nil) -> [Node]
  • In the case that there are more than one paths from the given source to the given destination, the path with the fewest edges is returned.

    Declaration

    Swift

    @inlinable
    public func shortestUnweightedPath(from source: Node, to destination: Node) -> [Node]?

    Return Value

    An array of Node values from the given source to the given destination.