SearchConfigConfiguration for DFS, BFS, and postorder graph traversals.
When to use
Use to configure the starting node indices and edge-following direction for lazy graph traversals.
Details
start supplies the node indices where traversal begins. If it is omitted,
the iterator is empty. direction chooses whether traversal follows
outgoing or incoming edges.
Gotchas
Traversal creation throws a GraphError when any configured start node
does not exist.
export interface SearchConfig {
readonly SearchConfig.start?: Array<NodeIndex>start?: interface Array<T>Array<type NodeIndex = numberNode index for node identification using plain numbers.
When to use
Use when storing or passing the stable identifier of a graph node between
Graph operations.
Details
addNode allocates node identifiers from the graph's next node index.
Gotchas
A NodeIndex is an identifier, not an array offset. Removed node identifiers
are not reused.
NodeIndex>
readonly SearchConfig.direction?: Directiondirection?: type Direction = "outgoing" | "incoming"Direction for graph traversal, indicating which edges to follow.
Example (Traversing by direction)
import { Graph } from "effect"
const graph = Graph.directed<string, string>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, "A->B")
})
// Follow outgoing edges (normal direction)
const outgoingNodes = Array.from(
Graph.indices(Graph.dfs(graph, { start: [0], direction: "outgoing" }))
)
// Follow incoming edges (reverse direction)
const incomingNodes = Array.from(
Graph.indices(Graph.dfs(graph, { start: [1], direction: "incoming" }))
)
Direction
}