DirectedAdjacencyList
public struct DirectedAdjacencyList<
Vertex: DefaultInitializable,
Edge: DefaultInitializable,
RawId: BinaryInteger & IdIndexable
>: DirectedAdjacencyListProtocol, SearchDefaultsGraph where RawId.Stride: SignedInteger
A general purpose directed adjacency list graph.
DirectedAdjacencyList implements a directed graph, and supports parallel edges.
DirectedAdjacencyList 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 ofVoid.
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.
DirectedAdjacencyList is parameterized by the RawId which can be carefully tuned to save
memory. A good default is UInt32, unless you are trying to represent more than 2^31 vertices,
or a lot of parallel edges.
-
Undocumented
Declaration
Swift
public typealias VertexId = RawId -
Undocumented
Declaration
Swift
public typealias EdgeId = _AdjacencyList_DirectedEdgeId<RawId> -
Undocumented
Declaration
Swift
public typealias VertexCollection = Range<RawId> -
Undocumented
Declaration
Swift
public typealias _EdgeData = _AdjacencyList_DirectedPerEdge<VertexId, Edge> -
Undocumented
Declaration
Swift
public typealias _VertexData = _AdjacencyList_DirectedPerVertex<Vertex, _EdgeData> -
Undocumented
Declaration
Swift
public typealias VertexEdgeCollection = _AdjacencyList_DirectedVertexEdgeCollection<_EdgeData> -
The collection of all edges in
self.Declaration
Swift
public typealias EdgeCollection = _AdjacencyList_DirectedEdgeCollection<_Storage> -
A parallel representation of
selfthat can be used in parallel algorithms.Declaration
Swift
public typealias ParallelProjection = _DirectedAdjacencyList_ParallelProjection<_VertexData> -
Undocumented
Declaration
Swift
public var _storage: _Storage -
Initialize an empty AdjacencyList.
Declaration
Swift
public init() -
All vertex identifiers.
Declaration
Swift
public var vertices: Range<RawId> { get }
-
All edges originating from
vertex.Declaration
Swift
public func edges(from vertex: VertexId) -> VertexEdgeCollection -
The number of edges originating from
vertex.Declaration
Swift
public func outDegree(of vertex: VertexId) -> Int
-
A reasonable color map implementation.
Declaration
Swift
public typealias DefaultColorMap = TablePropertyMap<`Self`, VertexId, VertexColor> -
Makes a default color map where every vertex is set to
color.Declaration
Swift
public func makeDefaultColorMap(repeating color: VertexColor) -> DefaultColorMap -
Makes a default int map for every vertex.
Declaration
Swift
public func makeDefaultVertexIntMap(repeating value: Int) -> TablePropertyMap<`Self`, VertexId, Int> -
Makes a default vertex property map mapping vertices.
Declaration
Swift
public func makeDefaultVertexVertexMap(repeating vertex: VertexId) -> TablePropertyMap<`Self`, VertexId, VertexId>
-
Hints
selfto reserve space for a total ofvertexCountvertices.Declaration
Swift
public mutating func reserveCapacity(vertexCount: Int) -
Removes all edges from
utov.If there are parallel edges, it removes all edges.
Precondition
uandvare vertices inself.Complexity
worst case O(|E|)Declaration
Return Value
true if one or more edges were removed; false otherwise.
-
Removes
edge.Declaration
Swift
public mutating func remove(_ edge: EdgeId) -
Removes all edges that
shouldBeRemoved.Declaration
Swift
public mutating func removeEdges(where shouldBeRemoved: (EdgeId, `Self`) -> Bool) -
Remove all out edges of
vertexthat satisfy the given predicate.Complexity
O(|E|)Declaration
-
Removes all edges from
vertex.Complexity
O(|E|)Declaration
Swift
public mutating func clear(vertex: VertexId) -
Removes
vertexfrom the graph.Complexity
O(|E| + |V|)Declaration
Swift
public mutating func remove(_ vertex: VertexId)
-
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
sourcetodestinationand associatededgeProperty, returning its identifier.Complexity
O(1) (amortized)Declaration
View on GitHub
DirectedAdjacencyList Structure Reference