WeightedGraphProtocol

public protocol WeightedGraphProtocol : GraphProtocol

Interface for weighted graphs.

Associated Type

  • The type of the weight of an Edge.

    Declaration

    Swift

    associatedtype Weight

Instance Properties

  • The storage of weights by the applicable edge.

    Declaration

    Swift

    var weights: [Edge : Weight] { get set }

Transforming into unweighted graphs

  • unweighted() Extension method

    Declaration

    Swift

    @inlinable
    public func unweighted<U>() -> U where U : UnweightedGraphProtocol, Self.Edge == U.Edge

    Return Value

    An unweighted version of this WeightedGraphProtocol-conforming type value.

Querying

  • edges Extension method

    Declaration

    Swift

    @inlinable
    public var edges: Set<Edge> { get }

    Return Value

    All of the edges contained herein.

  • weight(from:to:) Extension method

    Declaration

    Swift

    @inlinable
    public func weight(from source: Node, to destination: Node) -> Weight?

    Return Value

    The weight for the edge connecting the given source and destination nodes, if the given edge is contained herein. Otherwise, nil.

  • weight(_:) Extension method

    Declaration

    Swift

    @inlinable
    public func weight(_ edge: Edge) -> Weight?

    Return Value

    The weight for the given edge, if the given edge is contained herein. Otherwise, nil.

Modifying

  • insertEdge(from:to:weight:) Extension method

    Inserts an edge between the given source and destination nodes, with the given weight.

    If the source or destination nodes are not yet contained herein, they are inserted.

    Declaration

    Swift

    @inlinable
    public mutating func insertEdge(from source: Node, to destination: Node, weight: Weight)
  • remove(_:) Extension method

    Remove edge from graph.

    Declaration

    Swift

    @inlinable
    public mutating func remove(_ edge: Edge)
  • insertEdge(_:weight:) Extension method

    Inserts the given edge with the given weight.

    Declaration

    Swift

    @inlinable
    public mutating func insertEdge(_ edge: Edge, weight: Weight)
  • updateEdge(from:to:by:) Extension method

    Updates the weight of the edge between the given source and destination nodes by the given transform.

    Declaration

    Swift

    @inlinable
    public mutating func updateEdge(
        from source: Node,
        to destination: Node,
        by transform: (Weight) -> Weight
    )
  • updateEdge(_:by:) Extension method

    Updates the weight of the given edge by the given transform.

    Declaration

    Swift

    @inlinable
    public mutating func updateEdge(_ edge: Edge, by transform: (Weight) -> Weight)