From 6bae5fc5617a43d74e615aa7df71cc4a680bb8d2 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 9 Mar 2025 01:16:24 -0500 Subject: [PATCH] pgraph: Make our slow toposort even slower I think this makes it more deterministic, but I'm not sure it matters, since we are comparing based in the .String() property, and some nodes have the same value, so it ends up depending on the order they're added to the graph datastructure, but then we lose this information since it's a map. Yuck. --- pgraph/pgraph.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pgraph/pgraph.go b/pgraph/pgraph.go index fb3c8af2..32317f16 100644 --- a/pgraph/pgraph.go +++ b/pgraph/pgraph.go @@ -707,8 +707,13 @@ func (g *Graph) DeterministicTopologicalSort() ([]Vertex, error) { // kahn's alg v := S[last] S = S[:last] L = append(L, v) // add v to tail of L - // This doesn't need to loop in a deterministically sorted order. + + var vertices []Vertex for n := range g.adjacency[v] { // map[Vertex]Edge + vertices = append(vertices, n) + } + sort.Sort(VertexSlice(vertices)) // add determinism + for _, n := range vertices { // map[Vertex]Edge // for each node n remaining in the graph, consume from // remaining, so for remaining[n] > 0 if remaining[n] > 0 {