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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user