graph: add Empty universal iterator for empty returns

This commit is contained in:
Dan Kortschak
2018-12-13 07:56:04 +10:30
parent fd50e23eae
commit 14c7f9569f
29 changed files with 362 additions and 140 deletions

View File

@@ -169,7 +169,7 @@ func (g *Grid) NodeAt(r, c int) graph.Node {
// ends of an edge must be open.
func (g *Grid) From(uid int64) graph.Nodes {
if !g.HasOpen(uid) {
return nil
return graph.Empty
}
nr, nc := g.RowCol(uid)
var to []graph.Node
@@ -180,6 +180,9 @@ func (g *Grid) From(uid int64) graph.Nodes {
}
}
}
if len(to) == 0 {
return graph.Empty
}
return iterator.NewOrderedNodes(to)
}