graph/iterator: add lazy ordered node iterators
MODIFY
graph/iterator/nodes.go
graph/iterator/nodes.go
@@ -62,6 +62,313 @@ func (n *OrderedNodes) Reset() {
n.idx = -1
}
+// LazyOrderedNodes implements the graph.Nodes and graph.NodeSlicer interfaces.
+// The iteration order of LazyOrderedNodes is not determined until the first
+// call to Next or NodeSlice. After that, the iteration order is fixed.
+type LazyOrderedNodes struct {
+ iter OrderedNodes
+ nodes map[int64]graph.Node
+}
+
+// NewLazyOrderedNodes returns a LazyOrderedNodes initialized with the provided nodes.
+func NewLazyOrderedNodes(nodes map[int64]graph.Node) *LazyOrderedNodes {
+ return &LazyOrderedNodes{nodes: nodes}
+}
+
+// Len returns the remaining number of nodes to be iterated over.
+func (n *LazyOrderedNodes) Len() int {
+ if n.iter.nodes == nil {
+ return len(n.nodes)
+ }
+ return n.iter.Len()
+}
+
+// Next returns whether the next call of Node will return a valid node.
+func (n *LazyOrderedNodes) Next() bool {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.Next()
+}
+
+// Node returns the current node of the iterator. Next must have been
+// called prior to a call to Node.
+func (n *LazyOrderedNodes) Node() graph.Node {
+ return n.iter.Node()
+}
+
+// NodeSlice returns all the remaining nodes in the iterator and advances
+// the iterator.
+func (n *LazyOrderedNodes) NodeSlice() []graph.Node {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.NodeSlice()
+}
+
+// Reset returns the iterator to its initial state.
+func (n *LazyOrderedNodes) Reset() {
+ n.iter.Reset()
+}
+
+func (n *LazyOrderedNodes) fillSlice() {
+ n.iter = OrderedNodes{idx: -1, nodes: make([]graph.Node, len(n.nodes))}
+ i := 0
+ for _, u := range n.nodes {
+ n.iter.nodes[i] = u
+ i++
+ }
+ n.nodes = nil
+}
+
+// LazyOrderedNodesByEdge implements the graph.Nodes and graph.NodeSlicer interfaces.
+// The iteration order of LazyOrderedNodesByEdge is not determined until the first
+// call to Next or NodeSlice. After that, the iteration order is fixed.
+type LazyOrderedNodesByEdge struct {
+ iter OrderedNodes
+ nodes map[int64]graph.Node
+ edges map[int64]graph.Edge
+}
+
+// NewLazyOrderedNodesByEdge returns a LazyOrderedNodesByEdge initialized with the
+// provided nodes.
+func NewLazyOrderedNodesByEdge(nodes map[int64]graph.Node, edges map[int64]graph.Edge) *LazyOrderedNodesByEdge {
+ return &LazyOrderedNodesByEdge{nodes: nodes, edges: edges}
+}
+
+// Len returns the remaining number of nodes to be iterated over.
+func (n *LazyOrderedNodesByEdge) Len() int {
+ if n.iter.nodes == nil {
+ return len(n.edges)
+ }
+ return n.iter.Len()
+}
+
+// Next returns whether the next call of Node will return a valid node.
+func (n *LazyOrderedNodesByEdge) Next() bool {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.Next()
+}
+
+// Node returns the current node of the iterator. Next must have been
+// called prior to a call to Node.
+func (n *LazyOrderedNodesByEdge) Node() graph.Node {
+ return n.iter.Node()
+}
+
+// NodeSlice returns all the remaining nodes in the iterator and advances
+// the iterator.
+func (n *LazyOrderedNodesByEdge) NodeSlice() []graph.Node {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.NodeSlice()
+}
+
+// Reset returns the iterator to its initial state.
+func (n *LazyOrderedNodesByEdge) Reset() {
+ n.iter.Reset()
+}
+
+func (n *LazyOrderedNodesByEdge) fillSlice() {
+ n.iter = OrderedNodes{idx: -1, nodes: make([]graph.Node, len(n.edges))}
+ i := 0
+ for id := range n.edges {
+ n.iter.nodes[i] = n.nodes[id]
+ i++
+ }
+ n.nodes = nil
+ n.edges = nil
+}
+
+// LazyOrderedNodesByWeightedEdge implements the graph.Nodes and graph.NodeSlicer interfaces.
+// The iteration order of LazyOrderedNodesByEeightedEdge is not determined until the first
+// call to Next or NodeSlice. After that, the iteration order is fixed.
+type LazyOrderedNodesByWeightedEdge struct {
+ iter OrderedNodes
+ nodes map[int64]graph.Node
+ edges map[int64]graph.WeightedEdge
+}
+
+// NewLazyOrderedNodesByWeightedEdge returns a LazyOrderedNodesByEdge initialized with the
+// provided nodes.
+func NewLazyOrderedNodesByWeightedEdge(nodes map[int64]graph.Node, edges map[int64]graph.WeightedEdge) *LazyOrderedNodesByWeightedEdge {
+ return &LazyOrderedNodesByWeightedEdge{nodes: nodes, edges: edges}
+}
+
+// Len returns the remaining number of nodes to be iterated over.
+func (n *LazyOrderedNodesByWeightedEdge) Len() int {
+ if n.iter.nodes == nil {
+ return len(n.edges)
+ }
+ return n.iter.Len()
+}
+
+// Next returns whether the next call of Node will return a valid node.
+func (n *LazyOrderedNodesByWeightedEdge) Next() bool {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.Next()
+}
+
+// Node returns the current node of the iterator. Next must have been
+// called prior to a call to Node.
+func (n *LazyOrderedNodesByWeightedEdge) Node() graph.Node {
+ return n.iter.Node()
+}
+
+// NodeSlice returns all the remaining nodes in the iterator and advances
+// the iterator.
+func (n *LazyOrderedNodesByWeightedEdge) NodeSlice() []graph.Node {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.NodeSlice()
+}
+
+// Reset returns the iterator to its initial state.
+func (n *LazyOrderedNodesByWeightedEdge) Reset() {
+ n.iter.Reset()
+}
+
+func (n *LazyOrderedNodesByWeightedEdge) fillSlice() {
+ n.iter = OrderedNodes{idx: -1, nodes: make([]graph.Node, len(n.edges))}
+ i := 0
+ for id := range n.edges {
+ n.iter.nodes[i] = n.nodes[id]
+ i++
+ }
+ n.nodes = nil
+ n.edges = nil
+}
+
+// LazyOrderedNodesByLines implements the graph.Nodes and graph.NodeSlicer interfaces.
+// The iteration order of LazyOrderedNodesByLines is not determined until the first
+// call to Next or NodeSlice. After that, the iteration order is fixed.
+type LazyOrderedNodesByLines struct {
+ iter OrderedNodes
+ nodes map[int64]graph.Node
+ edges map[int64]map[int64]graph.Line
+}
+
+// NewLazyOrderedNodesByLine returns a LazyOrderedNodesByLines initialized with the
+// provided nodes.
+func NewLazyOrderedNodesByLines(nodes map[int64]graph.Node, edges map[int64]map[int64]graph.Line) *LazyOrderedNodesByLines {
+ return &LazyOrderedNodesByLines{nodes: nodes, edges: edges}
+}
+
+// Len returns the remaining number of nodes to be iterated over.
+func (n *LazyOrderedNodesByLines) Len() int {
+ if n.iter.nodes == nil {
+ return len(n.edges)
+ }
+ return n.iter.Len()
+}
+
+// Next returns whether the next call of Node will return a valid node.
+func (n *LazyOrderedNodesByLines) Next() bool {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.Next()
+}
+
+// Node returns the current node of the iterator. Next must have been
+// called prior to a call to Node.
+func (n *LazyOrderedNodesByLines) Node() graph.Node {
+ return n.iter.Node()
+}
+
+// NodeSlice returns all the remaining nodes in the iterator and advances
+// the iterator.
+func (n *LazyOrderedNodesByLines) NodeSlice() []graph.Node {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.NodeSlice()
+}
+
+// Reset returns the iterator to its initial state.
+func (n *LazyOrderedNodesByLines) Reset() {
+ n.iter.Reset()
+}
+
+func (n *LazyOrderedNodesByLines) fillSlice() {
+ n.iter = OrderedNodes{idx: -1, nodes: make([]graph.Node, len(n.edges))}
+ i := 0
+ for id := range n.edges {
+ n.iter.nodes[i] = n.nodes[id]
+ i++
+ }
+ n.nodes = nil
+ n.edges = nil
+}
+
+// LazyOrderedNodesByWeightedLines implements the graph.Nodes and graph.NodeSlicer interfaces.
+// The iteration order of LazyOrderedNodesByEeightedLine is not determined until the first
+// call to Next or NodeSlice. After that, the iteration order is fixed.
+type LazyOrderedNodesByWeightedLines struct {
+ iter OrderedNodes
+ nodes map[int64]graph.Node
+ edges map[int64]map[int64]graph.WeightedLine
+}
+
+// NewLazyOrderedNodesByWeightedLines returns a LazyOrderedNodesByLines initialized with the
+// provided nodes.
+func NewLazyOrderedNodesByWeightedLines(nodes map[int64]graph.Node, edges map[int64]map[int64]graph.WeightedLine) *LazyOrderedNodesByWeightedLines {
+ return &LazyOrderedNodesByWeightedLines{nodes: nodes, edges: edges}
+}
+
+// Len returns the remaining number of nodes to be iterated over.
+func (n *LazyOrderedNodesByWeightedLines) Len() int {
+ if n.iter.nodes == nil {
+ return len(n.edges)
+ }
+ return n.iter.Len()
+}
+
+// Next returns whether the next call of Node will return a valid node.
+func (n *LazyOrderedNodesByWeightedLines) Next() bool {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.Next()
+}
+
+// Node returns the current node of the iterator. Next must have been
+// called prior to a call to Node.
+func (n *LazyOrderedNodesByWeightedLines) Node() graph.Node {
+ return n.iter.Node()
+}
+
+// NodeSlice returns all the remaining nodes in the iterator and advances
+// the iterator.
+func (n *LazyOrderedNodesByWeightedLines) NodeSlice() []graph.Node {
+ if n.iter.nodes == nil {
+ n.fillSlice()
+ }
+ return n.iter.NodeSlice()
+}
+
+// Reset returns the iterator to its initial state.
+func (n *LazyOrderedNodesByWeightedLines) Reset() {
+ n.iter.Reset()
+}
+
+func (n *LazyOrderedNodesByWeightedLines) fillSlice() {
+ n.iter = OrderedNodes{idx: -1, nodes: make([]graph.Node, len(n.edges))}
+ i := 0
+ for id := range n.edges {
+ n.iter.nodes[i] = n.nodes[id]
+ i++
+ }
+ n.nodes = nil
+ n.edges = nil
+}
+
// ImplicitNodes implements the graph.Nodes interface for a set of nodes over
// a contiguous ID range.
type ImplicitNodes struct {

MODIFY
graph/iterator/nodes_test.go
graph/iterator/nodes_test.go
@@ -116,9 +116,17 @@ var nodesTests = []struct {
{nodes: map[int64]graph.Node{5: simple.Node(5), 3: simple.Node(3), 2: simple.Node(2), 1: simple.Node(1)}},
}
-func TestNodesIterate(t *testing.T) {
+func TestIterateNodes(t *testing.T) {
+ for _, typ := range []struct {
+ name string
+ new func(map[int64]graph.Node) graph.Nodes
+ }{
+ {name: "Nodes", new: func(n map[int64]graph.Node) graph.Nodes { return iterator.NewNodes(n) }},
+ {name: "LazyOrderedNodes", new: func(n map[int64]graph.Node) graph.Nodes { return iterator.NewLazyOrderedNodes(n) }},
+ } {
+ t.Run(typ.name, func(t *testing.T) {
for _, test := range nodesTests {
- it := iterator.NewNodes(test.nodes)
+ it := typ.new(test.nodes)
for i := 0; i < 2; i++ {
if it.Len() != len(test.nodes) {
t.Errorf("unexpected iterator length for round %d: got:%d want:%d", i, it.Len(), len(test.nodes))
@@ -150,6 +158,8 @@ func TestNodesIterate(t *testing.T) {
it.Reset()
}
}
+ })
+ }
}
var nodesByEdgeTests = []struct {
@@ -188,13 +198,30 @@ var nodesByEdgeTests = []struct {
}
func TestNodesByEdgeIterate(t *testing.T) {
+ for _, typ := range []struct {
+ name string
+ new func(map[int64]graph.Node, map[int64]graph.Edge) graph.Nodes
+ }{
+ {
+ name: "NodesByEdge",
+ new: func(n map[int64]graph.Node, e map[int64]graph.Edge) graph.Nodes {
+ return iterator.NewNodesByEdge(n, e)
+ }},
+ {
+ name: "LazyOrderedNodesByEdge",
+ new: func(n map[int64]graph.Node, e map[int64]graph.Edge) graph.Nodes {
+ return iterator.NewLazyOrderedNodesByEdge(n, e)
+ },
+ },
+ } {
+ t.Run(typ.name, func(t *testing.T) {
for _, test := range nodesByEdgeTests {
nodes := make(map[int64]graph.Node)
for i := int64(0); i < test.n; i++ {
nodes[i] = simple.Node(i)
}
- it := iterator.NewNodesByEdge(nodes, test.edges)
+ it := typ.new(nodes, test.edges)
for i := 0; i < 2; i++ {
if it.Len() != len(test.edges) {
t.Errorf("unexpected iterator length for round %d: got:%d want:%d", i, it.Len(), len(nodes))
@@ -225,6 +252,8 @@ func TestNodesByEdgeIterate(t *testing.T) {
it.Reset()
}
}
+ })
+ }
}
var nodesByWeightedEdgeTests = []struct {
@@ -263,13 +292,30 @@ var nodesByWeightedEdgeTests = []struct {
}
func TestNodesByWeightedEdgeIterate(t *testing.T) {
+ for _, typ := range []struct {
+ name string
+ new func(map[int64]graph.Node, map[int64]graph.WeightedEdge) graph.Nodes
+ }{
+ {
+ name: "NodesByWeightedEdge",
+ new: func(n map[int64]graph.Node, e map[int64]graph.WeightedEdge) graph.Nodes {
+ return iterator.NewNodesByWeightedEdge(n, e)
+ }},
+ {
+ name: "LazyOrderedNodesByWeightedEdge",
+ new: func(n map[int64]graph.Node, e map[int64]graph.WeightedEdge) graph.Nodes {
+ return iterator.NewLazyOrderedNodesByWeightedEdge(n, e)
+ },
+ },
+ } {
+ t.Run(typ.name, func(t *testing.T) {
for _, test := range nodesByWeightedEdgeTests {
nodes := make(map[int64]graph.Node)
for i := int64(0); i < test.n; i++ {
nodes[i] = simple.Node(i)
}
- it := iterator.NewNodesByWeightedEdge(nodes, test.edges)
+ it := typ.new(nodes, test.edges)
for i := 0; i < 2; i++ {
if it.Len() != len(test.edges) {
t.Errorf("unexpected iterator length for round %d: got:%d want:%d", i, it.Len(), len(nodes))
@@ -300,6 +346,8 @@ func TestNodesByWeightedEdgeIterate(t *testing.T) {
it.Reset()
}
}
+ })
+ }
}
var nodesByLinesTests = []struct {
@@ -338,13 +386,30 @@ var nodesByLinesTests = []struct {
}
func TestNodesByLinesIterate(t *testing.T) {
+ for _, typ := range []struct {
+ name string
+ new func(map[int64]graph.Node, map[int64]map[int64]graph.Line) graph.Nodes
+ }{
+ {
+ name: "NodesByLines",
+ new: func(n map[int64]graph.Node, e map[int64]map[int64]graph.Line) graph.Nodes {
+ return iterator.NewNodesByLines(n, e)
+ }},
+ {
+ name: "LazyOrderedNodesByLines",
+ new: func(n map[int64]graph.Node, e map[int64]map[int64]graph.Line) graph.Nodes {
+ return iterator.NewLazyOrderedNodesByLines(n, e)
+ },
+ },
+ } {
+ t.Run(typ.name, func(t *testing.T) {
for _, test := range nodesByLinesTests {
nodes := make(map[int64]graph.Node)
for i := int64(0); i < test.n; i++ {
nodes[i] = simple.Node(i)
}
- it := iterator.NewNodesByLines(nodes, test.lines)
+ it := typ.new(nodes, test.lines)
for i := 0; i < 2; i++ {
if it.Len() != len(test.lines) {
t.Errorf("unexpected iterator length for round %d: got:%d want:%d", i, it.Len(), len(nodes))
@@ -375,6 +440,8 @@ func TestNodesByLinesIterate(t *testing.T) {
it.Reset()
}
}
+ })
+ }
}
var nodesByWeightedLinesTests = []struct {
@@ -413,13 +480,30 @@ var nodesByWeightedLinesTests = []struct {
}
func TestNodesByWeightedLinesIterate(t *testing.T) {
+ for _, typ := range []struct {
+ name string
+ new func(map[int64]graph.Node, map[int64]map[int64]graph.WeightedLine) graph.Nodes
+ }{
+ {
+ name: "NodesByWeightedLines",
+ new: func(n map[int64]graph.Node, e map[int64]map[int64]graph.WeightedLine) graph.Nodes {
+ return iterator.NewNodesByWeightedLines(n, e)
+ }},
+ {
+ name: "LazyOrderedNodesByWeightedLines",
+ new: func(n map[int64]graph.Node, e map[int64]map[int64]graph.WeightedLine) graph.Nodes {
+ return iterator.NewLazyOrderedNodesByWeightedLines(n, e)
+ },
+ },
+ } {
+ t.Run(typ.name, func(t *testing.T) {
for _, test := range nodesByWeightedLinesTests {
nodes := make(map[int64]graph.Node)
for i := int64(0); i < test.n; i++ {
nodes[i] = simple.Node(i)
}
- it := iterator.NewNodesByWeightedLines(nodes, test.lines)
+ it := typ.new(nodes, test.lines)
for i := 0; i < 2; i++ {
if it.Len() != len(test.lines) {
t.Errorf("unexpected iterator length for round %d: got:%d want:%d", i, it.Len(), len(nodes))
@@ -450,6 +534,8 @@ func TestNodesByWeightedLinesIterate(t *testing.T) {
it.Reset()
}
}
+ })
+ }
}
type nodeSlicer interface {
@@ -496,6 +582,23 @@ var nodeSlicerTests = []struct {
want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
},
+ {
+ nodes: iterator.NewLazyOrderedNodes(map[int64]graph.Node{1: simple.Node(1)}),
+ want: []graph.Node{simple.Node(1)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodes(map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3)}),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodes(map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)}),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(4), simple.Node(5)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodes(map[int64]graph.Node{5: simple.Node(5), 3: simple.Node(3), 2: simple.Node(2), 1: simple.Node(1)}),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+
// The actual values of the edges stored in the edge
// map leading to each node are not used, so they are
// filled with nil values.
@@ -524,6 +627,94 @@ var nodeSlicerTests = []struct {
),
want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
},
+
+ {
+ nodes: iterator.NewLazyOrderedNodesByEdge(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]graph.Edge{1: nil},
+ ),
+ want: []graph.Node{simple.Node(1)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByEdge(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]graph.Edge{1: nil, 2: nil, 3: nil, 5: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByEdge(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]graph.Edge{5: nil, 3: nil, 2: nil, 1: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+
+ {
+ nodes: iterator.NewLazyOrderedNodesByWeightedEdge(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]graph.WeightedEdge{1: nil},
+ ),
+ want: []graph.Node{simple.Node(1)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByWeightedEdge(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]graph.WeightedEdge{1: nil, 2: nil, 3: nil, 5: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByWeightedEdge(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]graph.WeightedEdge{5: nil, 3: nil, 2: nil, 1: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+
+ {
+ nodes: iterator.NewLazyOrderedNodesByLines(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]map[int64]graph.Line{1: nil},
+ ),
+ want: []graph.Node{simple.Node(1)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByLines(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]map[int64]graph.Line{1: nil, 2: nil, 3: nil, 5: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByLines(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]map[int64]graph.Line{5: nil, 3: nil, 2: nil, 1: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+
+ {
+ nodes: iterator.NewLazyOrderedNodesByWeightedLines(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]map[int64]graph.WeightedLine{1: nil},
+ ),
+ want: []graph.Node{simple.Node(1)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByWeightedLines(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]map[int64]graph.WeightedLine{1: nil, 2: nil, 3: nil, 5: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
+ {
+ nodes: iterator.NewLazyOrderedNodesByWeightedLines(
+ map[int64]graph.Node{1: simple.Node(1), 2: simple.Node(2), 3: simple.Node(3), 4: simple.Node(4), 5: simple.Node(5)},
+ map[int64]map[int64]graph.WeightedLine{5: nil, 3: nil, 2: nil, 1: nil},
+ ),
+ want: []graph.Node{simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(5)},
+ },
}
func TestNodeSlicers(t *testing.T) {

graph/iterator: add lazy ordered node iterators