@@ -447,60 +447,50 @@ func union(t0, t1 *Pot, pof Pof) (*Pot, int) {
447447 return n , common
448448}
449449
450- // Each called with (f) is a synchronous iterator over the bins of a node
451- // respecting an ordering
452- // proximity > pinnedness
453- func (t * Pot ) Each (f func (Val , int ) bool ) bool {
450+ // Each is a synchronous iterator over the elements of pot with function f.
451+ func (t * Pot ) Each (f func (Val ) bool ) bool {
454452 return t .each (f )
455453}
456454
457- func (t * Pot ) each (f func (Val , int ) bool ) bool {
458- var next bool
455+ // each is a synchronous iterator over the elements of pot with function f.
456+ // the iteration ends if the function return false or there are no more elements.
457+ func (t * Pot ) each (f func (Val ) bool ) bool {
458+ if t == nil || t .size == 0 {
459+ return false
460+ }
459461 for _ , n := range t .bins {
460- if n == nil {
461- return true
462- }
463- next = n .each (f )
464- if ! next {
462+ if ! n .each (f ) {
465463 return false
466464 }
467465 }
468- if t .size == 0 {
469- return false
470- }
471- return f (t .pin , t .po )
466+ return f (t .pin )
472467}
473468
474- // eachFrom called with (f, start) is a synchronous iterator over the elements of a Pot
475- // within the inclusive range starting from proximity order start
476- // the function argument is passed the value and the proximity order wrt the root pin
477- // it does NOT include the pinned item of the root
478- // respecting an ordering
479- // proximity > pinnedness
480- // the iteration ends if the function return false or there are no more elements
481- // end of a po range can be implemented since po is passed to the function
482- func (t * Pot ) eachFrom (f func (Val , int ) bool , po int ) bool {
483- var next bool
484- _ , lim := t .getPos (po )
485- for i := lim ; i < len (t .bins ); i ++ {
486- n := t .bins [i ]
487- next = n .each (f )
488- if ! next {
469+ // eachFrom is a synchronous iterator over the elements of pot with function f,
470+ // starting from certain proximity order po, which is passed as a second parameter.
471+ // the iteration ends if the function return false or there are no more elements.
472+ func (t * Pot ) eachFrom (f func (Val ) bool , po int ) bool {
473+ if t == nil || t .size == 0 {
474+ return false
475+ }
476+ _ , beg := t .getPos (po )
477+ for i := beg ; i < len (t .bins ); i ++ {
478+ if ! t .bins [i ].each (f ) {
489479 return false
490480 }
491481 }
492- return f (t .pin , t . po )
482+ return f (t .pin )
493483}
494484
495485// EachBin iterates over bins of the pivot node and offers iterators to the caller on each
496486// subtree passing the proximity order and the size
497487// the iteration continues until the function's return value is false
498488// or there are no more subtries
499- func (t * Pot ) EachBin (val Val , pof Pof , po int , f func (int , int , func (func (val Val , i int ) bool ) bool ) bool ) {
489+ func (t * Pot ) EachBin (val Val , pof Pof , po int , f func (int , int , func (func (val Val ) bool ) bool ) bool ) {
500490 t .eachBin (val , pof , po , f )
501491}
502492
503- func (t * Pot ) eachBin (val Val , pof Pof , po int , f func (int , int , func (func (val Val , i int ) bool ) bool ) bool ) {
493+ func (t * Pot ) eachBin (val Val , pof Pof , po int , f func (int , int , func (func (val Val ) bool ) bool ) bool ) {
504494 if t == nil || t .size == 0 {
505495 return
506496 }
@@ -520,8 +510,8 @@ func (t *Pot) eachBin(val Val, pof Pof, po int, f func(int, int, func(func(val V
520510 }
521511 if lim == len (t .bins ) {
522512 if spr >= po {
523- f (spr , 1 , func (g func (Val , int ) bool ) bool {
524- return g (t .pin , spr )
513+ f (spr , 1 , func (g func (Val ) bool ) bool {
514+ return g (t .pin )
525515 })
526516 }
527517 return
@@ -535,9 +525,9 @@ func (t *Pot) eachBin(val Val, pof Pof, po int, f func(int, int, func(func(val V
535525 size += n .size
536526 }
537527 if spr >= po {
538- if ! f (spr , t .size - size , func (g func (Val , int ) bool ) bool {
539- return t .eachFrom (func (v Val , j int ) bool {
540- return g (v , spr )
528+ if ! f (spr , t .size - size , func (g func (Val ) bool ) bool {
529+ return t .eachFrom (func (v Val ) bool {
530+ return g (v )
541531 }, spo )
542532 }) {
543533 return
@@ -585,7 +575,7 @@ func (t *Pot) eachNeighbour(val Val, pof Pof, f func(Val, int) bool) bool {
585575 }
586576
587577 for i := l - 1 ; i > ir ; i -- {
588- next = t .bins [i ].each (func (v Val , _ int ) bool {
578+ next = t .bins [i ].each (func (v Val ) bool {
589579 return f (v , po )
590580 })
591581 if ! next {
@@ -595,7 +585,7 @@ func (t *Pot) eachNeighbour(val Val, pof Pof, f func(Val, int) bool) bool {
595585
596586 for i := il - 1 ; i >= 0 ; i -- {
597587 n := t .bins [i ]
598- next = n .each (func (v Val , _ int ) bool {
588+ next = n .each (func (v Val ) bool {
599589 return f (v , n .po )
600590 })
601591 if ! next {
@@ -709,7 +699,7 @@ func (t *Pot) eachNeighbourAsync(val Val, pof Pof, max int, maxPos int, f func(V
709699 wg .Add (m )
710700 }
711701 go func (pn * Pot , pm int ) {
712- pn .each (func (v Val , _ int ) bool {
702+ pn .each (func (v Val ) bool {
713703 if wg != nil {
714704 defer wg .Done ()
715705 }
@@ -736,7 +726,7 @@ func (t *Pot) eachNeighbourAsync(val Val, pof Pof, max int, maxPos int, f func(V
736726 wg .Add (m )
737727 }
738728 go func (pn * Pot , pm int ) {
739- pn .each (func (v Val , _ int ) bool {
729+ pn .each (func (v Val ) bool {
740730 if wg != nil {
741731 defer wg .Done ()
742732 }
0 commit comments