Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrGraphHaveCycles = errors.New("the DAG have cycles")
)
Functions ¶
func DFS ¶
func DFS[T comparable](g DirectedGraph[T], startingNode T) ([]T, error)
depth first search with cycle detection
func TopologicalSort ¶
func TopologicalSort[T comparable](g DirectedGraph[T]) ([]T, error)
sort the nodes is topological order returns ErrGraphHaveCycles if the graph have cycles
Types ¶
type DirectedGraph ¶
type DirectedGraph[T comparable] interface { // get all nodes present Nodes() []T // get a list of nodes that the argument node depends on DependsOn(T) []T }
Click to show internal directories.
Click to hide internal directories.