Expand description
Graph traits and graph traversals.
The Into-
Traits
Graph traits like IntoNeighbors
create iterators and use the same
pattern that IntoIterator
does: the trait takes a reference to a graph,
and produces an iterator. These traits are quite composable, but with the
limitation that they only use shared references to graphs.
Graph Traversal
Dfs
, Bfs
, DfsPostOrder
and
Topo
are basic visitors and they use “walker” methods: the
visitors don’t hold the graph as borrowed during traversal, only for the
.next()
call on the walker. They can be converted to iterators
through the Walker
trait.
There is also the callback based traversal depth_first_search
.
Other Graph Traits
The traits are rather loosely coupled at the moment (which is intentional, but will develop a bit), and there are traits missing that could be added.
Not much is needed to be able to use the visitors on a graph. A graph
needs to define GraphBase
, IntoNeighbors
and
Visitable
as a minimum.
Graph Trait Implementations
The following table lists the traits that are implemented for each graph type:
Graph | StableGraph | GraphMap | MatrixGraph | Csr | List | |
---|---|---|---|---|---|---|
GraphBase | x | x | x | x | x | x |
GraphProp | x | x | x | x | x | x |
NodeCount | x | x | x | x | x | x |
NodeIndexable | x | x | x | x | x | x |
NodeCompactIndexable | x | x | x | x | ||
EdgeCount | x | x | x | x | x | x |
EdgeIndexable | x | x | x | |||
Data | x | x | x | x | x | x |
IntoNodeIdentifiers | x | x | x | x | x | x |
IntoNodeReferences | x | x | x | x | x | x |
IntoEdgeReferences | x | x | x | x | x | x |
IntoNeighbors | x | x | x | x | x | x |
IntoNeighborsDirected | x | x | x | x | ||
IntoEdges | x | x | x | x | x | x |
IntoEdgesDirected | x | x | x | x | ||
Visitable | x | x | x | x | x | x |
GetAdjacencyMatrix | x | x | x | x | x | x |
Structs
Enums
depth_first_search
callbacks.Traits
NodeId
s map to indicesNodeId
s.NodeId
s map to indices, in a range without holes.NodeId
s map to indicesN
.