Skip to content

Commit

Permalink
Add stability disclaimer for TopologicalSort
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikbraun committed May 24, 2023
1 parent 6a038f3 commit d2bb530
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ g := graph.New(graph.IntHash, graph.Directed(), graph.PreventCycles())

// Add vertices and edges ...

// For a deterministic topological ordering, use StableTopologicalSort.
order, _ := graph.TopologicalSort(g)

fmt.Println(order)
Expand Down
4 changes: 4 additions & 0 deletions dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
// order of vertices in a directed graph where an edge from vertex A to vertex B
// implies that vertex A appears before vertex B.
//
// Note that TopologicalSort doesn't make any guarantees about the order. If there
// are multiple valid topological orderings, an arbitrary one will be returned.
// To make the output deterministic, use [StableTopologicalSort].
//
// TopologicalSort only works for directed acyclic graphs. This implementation
// works non-recursively and utilizes Kahn's algorithm.
func TopologicalSort[K comparable, T any](g Graph[K, T]) ([]K, error) {
Expand Down

0 comments on commit d2bb530

Please sign in to comment.