• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

shamcode / simd / 12290622555

12 Dec 2024 05:46AM UTC coverage: 75.942% (-0.02%) from 75.964%
12290622555

push

github

shamcode
Add iter.Seq to Iterator

4 of 6 new or added lines in 1 file covered. (66.67%)

1875 of 2469 relevant lines covered (75.94%)

38.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/executor/iterator.go
1
package executor
2

3
import (
4
        "context"
5
        "iter"
6

7
        "github.com/shamcode/simd/record"
8
)
9

10
type Iterator[R record.Record] interface {
11
        Next(ctx context.Context) bool
12
        Item() R
13
        Size() int
14
        Err() error
15
        Seq(ctx context.Context) iter.Seq[R]
16
}
17

18
type heapIterator[R record.Record] struct {
19
        from      int
20
        index     int
21
        max       int
22
        size      int
23
        heap      *binaryHeap[R]
24
        lastError error
25
}
26

27
func (i *heapIterator[R]) Next(ctx context.Context) bool {
173✔
28
        select {
173✔
29
        case <-ctx.Done():
×
30
                i.lastError = ctx.Err()
×
31
                return false
×
32
        default:
173✔
33
                result := i.index < i.max
173✔
34
                if result {
292✔
35
                        i.index += 1
119✔
36
                }
119✔
37
                return result
173✔
38
        }
39
}
40

41
func (i *heapIterator[R]) Item() R {
120✔
42
        return i.heap.Remove(i.from)
120✔
43
}
120✔
44

45
func (i *heapIterator[R]) Err() error {
34✔
46
        return i.lastError
34✔
47
}
34✔
48

49
func (i *heapIterator[R]) Size() int {
52✔
50
        return i.size
52✔
51
}
52✔
52

53
func (i *heapIterator[R]) Seq(ctx context.Context) iter.Seq[R] {
21✔
54
        return func(yield func(R) bool) {
42✔
55
                for i.Next(ctx) {
71✔
56
                        if !yield(i.Item()) {
50✔
NEW
57
                                return
×
NEW
58
                        }
×
59
                }
60
        }
61
}
62

63
func newHeapIterator[R record.Record](heap *binaryHeap[R], from, to, size int) Iterator[R] {
78✔
64
        return &heapIterator[R]{ //nolint:exhaustruct
78✔
65
                from:  from,
78✔
66
                index: from,
78✔
67
                max:   to,
78✔
68
                size:  size,
78✔
69
                heap:  heap,
78✔
70
        }
78✔
71
}
78✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc