From 0a64b086698c745d61fc85220663f93cf0c644cf Mon Sep 17 00:00:00 2001 From: James Shubin Date: Fri, 2 Jun 2017 22:29:42 -0400 Subject: [PATCH] resources: autoedges: Process in a deterministic order The order you loop through map's isn't necessarily stable, so make sure you sort everything before you go through it. --- resources/autoedge.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/autoedge.go b/resources/autoedge.go index 54c65375..a7326ecb 100644 --- a/resources/autoedge.go +++ b/resources/autoedge.go @@ -94,8 +94,9 @@ func AutoEdges(g *pgraph.Graph) error { // initially get all of the autoedges to seek out all possible errors var err error autoEdgeObjVertexMap := make(map[pgraph.Vertex]AutoEdge) + sorted := g.VerticesSorted() - for _, v := range g.VerticesSorted() { // for each vertexes autoedges + for _, v := range sorted { // for each vertexes autoedges if !VtoR(v).Meta().AutoEdge { // is the metaparam true? continue } @@ -115,8 +116,12 @@ func AutoEdges(g *pgraph.Graph) error { } // now that we're guaranteed error free, we can modify the graph safely - // TODO: loop through this in a sorted order for stable log output... - for v, autoEdgeObj := range autoEdgeObjVertexMap { + for _, v := range sorted { // stable sort order for determinism in logs + autoEdgeObj, exists := autoEdgeObjVertexMap[v] + if !exists { + continue + } + for { // while the autoEdgeObj has more uids to add... uids := autoEdgeObj.Next() // get some! if uids == nil {