Graph walking algorithms — BFS and DFS traversals with fold support and path finding.
Summary
Functions
Finds the shortest path between two nodes using BFS.
Folds over nodes during graph traversal, accumulating state with metadata.
Walks the graph starting from the given node, visiting all reachable nodes.
Walks the graph but stops early when a condition is met.
Types
@type order() :: :breadth_first | :depth_first
@type walk_control() :: :continue | :stop | :halt
@type walk_metadata() :: %{depth: integer(), parent: Yog.node_id() | nil}
Functions
@spec find_path(Yog.graph(), Yog.node_id(), Yog.node_id()) :: [Yog.node_id()] | nil
Finds the shortest path between two nodes using BFS.
Folds over nodes during graph traversal, accumulating state with metadata.
@spec fold_walk( Yog.graph(), Yog.node_id(), order(), acc, (acc, Yog.node_id(), walk_metadata() -> {walk_control(), acc}) ) :: acc when acc: var
@spec walk(keyword()) :: [Yog.node_id()]
Walks the graph starting from the given node, visiting all reachable nodes.
Options
:from- Starting node ID:in- The graph to traverse:using- Traversal order (:breadth_firstor:depth_first)
@spec walk(Yog.graph(), Yog.node_id(), order()) :: [Yog.node_id()]
@spec walk_until(keyword()) :: [Yog.node_id()]
Walks the graph but stops early when a condition is met.
@spec walk_until(Yog.graph(), Yog.node_id(), order(), (Yog.node_id() -> boolean())) :: [Yog.node_id()]