# Module petgraph::visit
[−]
[src]

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.

## Structs

Bfs |
A breadth first search (BFS) of a graph. |

Dfs |
Visit nodes of a graph in a depth-first-search (DFS) emitting nodes in preorder (when they are first discovered). |

DfsPostOrder |
Visit nodes in a depth-first-search (DFS) emitting nodes in postorder (each node after all its decendants have been emitted). |

EdgeFiltered |
An edge-filtering graph adaptor. |

EdgeFilteredEdges |
A filtered edges iterator. |

EdgeFilteredNeighbors |
A filtered neighbors iterator. |

NodeFiltered |
A node-filtering graph adaptor. |

NodeFilteredEdgeReferences |
A filtered edges iterator. |

NodeFilteredEdges |
A filtered edges iterator. |

NodeFilteredNeighbors |
A filtered neighbors iterator. |

NodeFilteredNodes |
A filtered node references iterator. |

Reversed |
An edge-reversing graph adaptor. |

ReversedEdgeReference |
A reversed edge reference |

ReversedEdgeReferences |
A reversed edge references iterator. |

Time |
Strictly monotonically increasing event time for a depth first search. |

Topo |
A topological order traversal for a graph. |

WalkerIter |
A walker and its context wrapped into an iterator. |

## Enums

Control |
Control flow for callbacks. |

DfsEvent |
A depth first search (DFS) visitor event. |

## Traits

ControlFlow |
Control flow for callbacks. |

Data |
Define associated data for nodes and edges |

EdgeRef |
An edge reference. |

FilterEdge |
A graph filter for edges |

FilterNode |
A graph filter for nodes. |

GetAdjacencyMatrix |
Create or access the adjacency matrix of a graph. |

GraphBase |
Base graph trait: defines the associated node identifier and edge identifier types. |

GraphProp |
Edge kind property (directed or undirected edges) |

GraphRef |
A copyable reference to a graph. |

IntoEdgeReferences |
Access to the sequence of the graph’s edges |

IntoEdges |
Access to the edges of each node. |

IntoNeighbors |
Access to the neighbors of each node |

IntoNeighborsDirected |
Access to the neighbors of each node, through incoming or outgoing edges. |

IntoNodeIdentifiers |
Access to the sequence of the graph’s |

IntoNodeReferences |
Access to the sequence of the graph’s nodes |

NodeCompactIndexable |
The graph’s |

NodeCount |
A graph with a known node count. |

NodeIndexable |
The graph’s |

NodeRef |
A node reference. |

VisitMap |
A mapping for storing the visited status for NodeId |

Visitable |
A graph that can create a map that tracks the visited status of its nodes. |

Walker |
A walker is a traversal state, but where part of the traversal information is supplied manually to each next call. |

## Functions

depth_first_search |
A recursive depth first search. |