mirror of
https://github.com/gonum/gonum.git
synced 2025-10-08 00:20:11 +08:00
graph: fix nodeIteratorPair bug revealed by lazy iterators
This commit is contained in:
@@ -229,7 +229,9 @@ func (e WeightedEdgePair) Weight() float64 { return e.W }
|
|||||||
type nodeIteratorPair struct {
|
type nodeIteratorPair struct {
|
||||||
a, b Nodes
|
a, b Nodes
|
||||||
|
|
||||||
curr, cnt int
|
curr Node
|
||||||
|
|
||||||
|
idx, cnt int
|
||||||
|
|
||||||
// unique indicates the node in b with the key ID is unique.
|
// unique indicates the node in b with the key ID is unique.
|
||||||
unique map[int64]bool
|
unique map[int64]bool
|
||||||
@@ -253,32 +255,33 @@ func newNodeIteratorPair(a, b Nodes) *nodeIteratorPair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *nodeIteratorPair) Len() int {
|
func (n *nodeIteratorPair) Len() int {
|
||||||
return n.cnt - n.curr
|
return n.cnt - n.idx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nodeIteratorPair) Next() bool {
|
func (n *nodeIteratorPair) Next() bool {
|
||||||
if n.a.Next() {
|
if n.a.Next() {
|
||||||
n.curr++
|
n.idx++
|
||||||
|
n.curr = n.a.Node()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for n.b.Next() {
|
for n.b.Next() {
|
||||||
if n.unique[n.b.Node().ID()] {
|
if n.unique[n.b.Node().ID()] {
|
||||||
n.curr++
|
n.idx++
|
||||||
|
n.curr = n.b.Node()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
n.curr = nil
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nodeIteratorPair) Node() Node {
|
func (n *nodeIteratorPair) Node() Node {
|
||||||
if n.a.Len() != 0 {
|
return n.curr
|
||||||
return n.a.Node()
|
|
||||||
}
|
|
||||||
return n.b.Node()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nodeIteratorPair) Reset() {
|
func (n *nodeIteratorPair) Reset() {
|
||||||
n.curr = 0
|
n.idx = 0
|
||||||
|
n.curr = nil
|
||||||
n.a.Reset()
|
n.a.Reset()
|
||||||
n.b.Reset()
|
n.b.Reset()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user