-
Notifications
You must be signed in to change notification settings - Fork 4
/
smdirtyreader_iterator.go
53 lines (45 loc) · 1.19 KB
/
smdirtyreader_iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package datawriter
import (
"github.com/insolar/assured-ledger/ledger-core/ledger"
"github.com/insolar/assured-ledger/ledger-core/ledger/server/dataextractor"
"github.com/insolar/assured-ledger/ledger-core/reference"
"github.com/insolar/assured-ledger/ledger-core/vanilla/throw"
)
var _ dataextractor.Iterator = &dirtyIterator{}
type dirtyIterator struct {
direction dataextractor.Direction
entries []ledger.DirectoryIndex
index int
}
func (p *dirtyIterator) Direction() dataextractor.Direction {
return p.direction
}
func (p *dirtyIterator) CurrentEntry() ledger.DirectoryIndex {
switch {
case p.index <= 0:
panic(throw.IllegalState())
case p.index > len(p.entries):
panic(throw.IllegalState())
default:
return p.entries[p.index - 1]
}
}
func (p *dirtyIterator) ExtraEntries() []ledger.DirectoryIndex {
return nil
}
func (p *dirtyIterator) Next(reference.Holder) (bool, error) {
switch n := len(p.entries); {
case p.index < n:
p.index++
return true, nil
case p.index == n:
p.index++
}
return false, nil
}
func (p *dirtyIterator) addExpected(entryIndex ledger.DirectoryIndex) {
if p.index != 0 {
panic(throw.IllegalState())
}
p.entries = append(p.entries, entryIndex)
}