dag: change the type sig of Update to Graph so its external friendly

This commit is contained in:
Mitchell Hashimoto 2017-02-03 11:11:37 +01:00
parent 28fff99ea8
commit 72a717f2de
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 15 additions and 13 deletions

View File

@ -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()
}

View File

@ -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.

View File

@ -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 {