dag: change the type sig of Update to Graph so its external friendly
This commit is contained in:
parent
28fff99ea8
commit
72a717f2de
|
@ -167,7 +167,7 @@ func (g *AcyclicGraph) Walk(cb WalkFunc) error {
|
||||||
defer g.debug.BeginOperation(typeWalk, "").End("")
|
defer g.debug.BeginOperation(typeWalk, "").End("")
|
||||||
|
|
||||||
w := &walker{Callback: cb, Reverse: true}
|
w := &walker{Callback: cb, Reverse: true}
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g.Graph)
|
||||||
return w.Wait()
|
return w.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,9 @@ func (w *walker) Wait() error {
|
||||||
// and edges. It does not block until completion.
|
// and edges. It does not block until completion.
|
||||||
//
|
//
|
||||||
// Update can be called in parallel to Walk.
|
// 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
|
// 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
|
// no new vertices are executed during this time since we may be
|
||||||
// removing them.
|
// removing them.
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestWalker_basic(t *testing.T) {
|
||||||
for i := 0; i < 50; i++ {
|
for i := 0; i < 50; i++ {
|
||||||
var order []interface{}
|
var order []interface{}
|
||||||
w := &walker{Callback: walkCbRecord(&order)}
|
w := &walker{Callback: walkCbRecord(&order)}
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Wait
|
// Wait
|
||||||
if err := w.Wait(); err != nil {
|
if err := w.Wait(); err != nil {
|
||||||
|
@ -57,7 +57,7 @@ func TestWalker_error(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
w := &walker{Callback: cb}
|
w := &walker{Callback: cb}
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Wait
|
// Wait
|
||||||
if err := w.Wait(); err == nil {
|
if err := w.Wait(); err == nil {
|
||||||
|
@ -81,18 +81,18 @@ func TestWalker_newVertex(t *testing.T) {
|
||||||
|
|
||||||
var order []interface{}
|
var order []interface{}
|
||||||
w := &walker{Callback: walkCbRecord(&order)}
|
w := &walker{Callback: walkCbRecord(&order)}
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Wait a bit
|
// Wait a bit
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
// Update the graph
|
// Update the graph
|
||||||
g.Add(3)
|
g.Add(3)
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Update the graph again but with the same vertex
|
// Update the graph again but with the same vertex
|
||||||
g.Add(3)
|
g.Add(3)
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Wait
|
// Wait
|
||||||
if err := w.Wait(); err != nil {
|
if err := w.Wait(); err != nil {
|
||||||
|
@ -124,7 +124,7 @@ func TestWalker_removeVertex(t *testing.T) {
|
||||||
cb := func(v Vertex) error {
|
cb := func(v Vertex) error {
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
g.Remove(2)
|
g.Remove(2)
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
}
|
}
|
||||||
|
|
||||||
return recordF(v)
|
return recordF(v)
|
||||||
|
@ -132,7 +132,7 @@ func TestWalker_removeVertex(t *testing.T) {
|
||||||
|
|
||||||
// Add the initial vertices
|
// Add the initial vertices
|
||||||
w = &walker{Callback: cb}
|
w = &walker{Callback: cb}
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Wait
|
// Wait
|
||||||
if err := w.Wait(); err != nil {
|
if err := w.Wait(); err != nil {
|
||||||
|
@ -165,7 +165,7 @@ func TestWalker_newEdge(t *testing.T) {
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
g.Add(3)
|
g.Add(3)
|
||||||
g.Connect(BasicEdge(3, 2))
|
g.Connect(BasicEdge(3, 2))
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
}
|
}
|
||||||
|
|
||||||
return recordF(v)
|
return recordF(v)
|
||||||
|
@ -173,7 +173,7 @@ func TestWalker_newEdge(t *testing.T) {
|
||||||
|
|
||||||
// Add the initial vertices
|
// Add the initial vertices
|
||||||
w = &walker{Callback: cb}
|
w = &walker{Callback: cb}
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Wait
|
// Wait
|
||||||
if err := w.Wait(); err != nil {
|
if err := w.Wait(); err != nil {
|
||||||
|
@ -214,7 +214,7 @@ func TestWalker_removeEdge(t *testing.T) {
|
||||||
cb := func(v Vertex) error {
|
cb := func(v Vertex) error {
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
g.RemoveEdge(BasicEdge(3, 2))
|
g.RemoveEdge(BasicEdge(3, 2))
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v == 2 {
|
if v == 2 {
|
||||||
|
@ -234,7 +234,7 @@ func TestWalker_removeEdge(t *testing.T) {
|
||||||
|
|
||||||
// Add the initial vertices
|
// Add the initial vertices
|
||||||
w = &walker{Callback: cb}
|
w = &walker{Callback: cb}
|
||||||
w.Update(g.vertices, g.edges)
|
w.Update(&g)
|
||||||
|
|
||||||
// Wait
|
// Wait
|
||||||
if err := w.Wait(); err != nil {
|
if err := w.Wait(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue