Documentation
¶
Overview ¶
Package dag provides generic graph algorithms that work with any data structure.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectCycleFn ¶
func DetectCycleFn[ID comparable](allIDs []ID, getDeps func(ID) []ID) []ID
DetectCycleFn detects a cycle in a graph using a higher-order function. Returns the cycle path if found, nil otherwise.
Parameters:
- allIDs: All node identifiers in the graph
- getDeps: Function that returns dependencies (children) for a given node
Example:
getDeps := func(id string) []string {
switch id {
case "A": return []string{"B", "C"}
case "B": return []string{"C"}
default: return nil
}
}
cycle := DetectCycleFn([]string{"A", "B", "C"}, getDeps)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.