Yog.Traversal.Walk (YogEx v0.70.0)

Copy Markdown View Source

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

order()

@type order() :: :breadth_first | :depth_first

walk_control()

@type walk_control() :: :continue | :stop | :halt

walk_metadata()

@type walk_metadata() :: %{depth: integer(), parent: Yog.node_id() | nil}

Functions

find_path(graph, from, to)

@spec find_path(Yog.graph(), Yog.node_id(), Yog.node_id()) :: [Yog.node_id()] | nil

Finds the shortest path between two nodes using BFS.

fold_walk(opts)

@spec fold_walk(keyword()) :: any()

Folds over nodes during graph traversal, accumulating state with metadata.

fold_walk(graph, from, order, initial, folder)

@spec fold_walk(
  Yog.graph(),
  Yog.node_id(),
  order(),
  acc,
  (acc, Yog.node_id(), walk_metadata() -> {walk_control(), acc})
) :: acc
when acc: var

walk(opts)

@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_first or :depth_first)

walk(graph, from, order)

@spec walk(Yog.graph(), Yog.node_id(), order()) :: [Yog.node_id()]

walk_until(opts)

@spec walk_until(keyword()) :: [Yog.node_id()]

Walks the graph but stops early when a condition is met.

walk_until(graph, from, order, should_stop)

@spec walk_until(Yog.graph(), Yog.node_id(), order(), (Yog.node_id() -> boolean())) ::
  [Yog.node_id()]