From 72a717f2de804d4fdc70b00e1eb9f3de7a0b7beb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Feb 2017 11:11:37 +0100 Subject: [PATCH] dag: change the type sig of Update to Graph so its external friendly --- dag/dag.go | 2 +- dag/walk.go | 4 +++- dag/walk_test.go | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dag/dag.go b/dag/dag.go index 4af78448b..4177cd07e 100644 --- a/dag/dag.go +++ b/dag/dag.go @@ -167,7 +167,7 @@ func (g *AcyclicGraph) Walk(cb WalkFunc) error { defer g.debug.BeginOperation(typeWalk, "").End("") w := &walker{Callback: cb, Reverse: true} - w.Update(g.vertices, g.edges) + w.Update(&g.Graph) return w.Wait() } diff --git a/dag/walk.go b/dag/walk.go index 30dd207a6..73045e0fe 100644 --- a/dag/walk.go +++ b/dag/walk.go @@ -98,7 +98,9 @@ func (w *walker) Wait() error { // and edges. It does not block until completion. // // Update can be called in parallel to Walk. -func (w *walker) Update(v, e *Set) { +func (w *walker) Update(g *Graph) { + v, e := g.vertices, g.edges + // Grab the change lock so no more updates happen but also so that // no new vertices are executed during this time since we may be // removing them. diff --git a/dag/walk_test.go b/dag/walk_test.go index 9927eb48e..8f99d9046 100644 --- a/dag/walk_test.go +++ b/dag/walk_test.go @@ -18,7 +18,7 @@ func TestWalker_basic(t *testing.T) { for i := 0; i < 50; i++ { var order []interface{} w := &walker{Callback: walkCbRecord(&order)} - w.Update(g.vertices, g.edges) + w.Update(&g) // Wait if err := w.Wait(); err != nil { @@ -57,7 +57,7 @@ func TestWalker_error(t *testing.T) { } w := &walker{Callback: cb} - w.Update(g.vertices, g.edges) + w.Update(&g) // Wait if err := w.Wait(); err == nil { @@ -81,18 +81,18 @@ func TestWalker_newVertex(t *testing.T) { var order []interface{} w := &walker{Callback: walkCbRecord(&order)} - w.Update(g.vertices, g.edges) + w.Update(&g) // Wait a bit time.Sleep(10 * time.Millisecond) // Update the graph g.Add(3) - w.Update(g.vertices, g.edges) + w.Update(&g) // Update the graph again but with the same vertex g.Add(3) - w.Update(g.vertices, g.edges) + w.Update(&g) // Wait if err := w.Wait(); err != nil { @@ -124,7 +124,7 @@ func TestWalker_removeVertex(t *testing.T) { cb := func(v Vertex) error { if v == 1 { g.Remove(2) - w.Update(g.vertices, g.edges) + w.Update(&g) } return recordF(v) @@ -132,7 +132,7 @@ func TestWalker_removeVertex(t *testing.T) { // Add the initial vertices w = &walker{Callback: cb} - w.Update(g.vertices, g.edges) + w.Update(&g) // Wait if err := w.Wait(); err != nil { @@ -165,7 +165,7 @@ func TestWalker_newEdge(t *testing.T) { if v == 1 { g.Add(3) g.Connect(BasicEdge(3, 2)) - w.Update(g.vertices, g.edges) + w.Update(&g) } return recordF(v) @@ -173,7 +173,7 @@ func TestWalker_newEdge(t *testing.T) { // Add the initial vertices w = &walker{Callback: cb} - w.Update(g.vertices, g.edges) + w.Update(&g) // Wait if err := w.Wait(); err != nil { @@ -214,7 +214,7 @@ func TestWalker_removeEdge(t *testing.T) { cb := func(v Vertex) error { if v == 1 { g.RemoveEdge(BasicEdge(3, 2)) - w.Update(g.vertices, g.edges) + w.Update(&g) } if v == 2 { @@ -234,7 +234,7 @@ func TestWalker_removeEdge(t *testing.T) { // Add the initial vertices w = &walker{Callback: cb} - w.Update(g.vertices, g.edges) + w.Update(&g) // Wait if err := w.Wait(); err != nil {