@@ -447,60 +447,50 @@ func union(t0, t1 *Pot, pof Pof) (*Pot, int) {
447
447
return n , common
448
448
}
449
449
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 {
454
452
return t .each (f )
455
453
}
456
454
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
+ }
459
461
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 ) {
465
463
return false
466
464
}
467
465
}
468
- if t .size == 0 {
469
- return false
470
- }
471
- return f (t .pin , t .po )
466
+ return f (t .pin )
472
467
}
473
468
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 ) {
489
479
return false
490
480
}
491
481
}
492
- return f (t .pin , t . po )
482
+ return f (t .pin )
493
483
}
494
484
495
485
// EachBin iterates over bins of the pivot node and offers iterators to the caller on each
496
486
// subtree passing the proximity order and the size
497
487
// the iteration continues until the function's return value is false
498
488
// 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 ) {
500
490
t .eachBin (val , pof , po , f )
501
491
}
502
492
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 ) {
504
494
if t == nil || t .size == 0 {
505
495
return
506
496
}
@@ -520,8 +510,8 @@ func (t *Pot) eachBin(val Val, pof Pof, po int, f func(int, int, func(func(val V
520
510
}
521
511
if lim == len (t .bins ) {
522
512
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 )
525
515
})
526
516
}
527
517
return
@@ -535,9 +525,9 @@ func (t *Pot) eachBin(val Val, pof Pof, po int, f func(int, int, func(func(val V
535
525
size += n .size
536
526
}
537
527
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 )
541
531
}, spo )
542
532
}) {
543
533
return
@@ -585,7 +575,7 @@ func (t *Pot) eachNeighbour(val Val, pof Pof, f func(Val, int) bool) bool {
585
575
}
586
576
587
577
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 {
589
579
return f (v , po )
590
580
})
591
581
if ! next {
@@ -595,7 +585,7 @@ func (t *Pot) eachNeighbour(val Val, pof Pof, f func(Val, int) bool) bool {
595
585
596
586
for i := il - 1 ; i >= 0 ; i -- {
597
587
n := t .bins [i ]
598
- next = n .each (func (v Val , _ int ) bool {
588
+ next = n .each (func (v Val ) bool {
599
589
return f (v , n .po )
600
590
})
601
591
if ! next {
@@ -709,7 +699,7 @@ func (t *Pot) eachNeighbourAsync(val Val, pof Pof, max int, maxPos int, f func(V
709
699
wg .Add (m )
710
700
}
711
701
go func (pn * Pot , pm int ) {
712
- pn .each (func (v Val , _ int ) bool {
702
+ pn .each (func (v Val ) bool {
713
703
if wg != nil {
714
704
defer wg .Done ()
715
705
}
@@ -736,7 +726,7 @@ func (t *Pot) eachNeighbourAsync(val Val, pof Pof, max int, maxPos int, f func(V
736
726
wg .Add (m )
737
727
}
738
728
go func (pn * Pot , pm int ) {
739
- pn .each (func (v Val , _ int ) bool {
729
+ pn .each (func (v Val ) bool {
740
730
if wg != nil {
741
731
defer wg .Done ()
742
732
}
0 commit comments