blob: f15498e2fee0d6de9997e9b51be4e54e7bf6028b (
plain) (
blame)
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
|
package set
type Iterator struct {
bucketIds []int
vals map[int][]interface{}
bucketIdx int
valIdx int
}
func (it *Iterator) Value() interface{} {
return it.currentBucket()[it.valIdx]
}
func (it *Iterator) Next() bool {
if it.bucketIdx == -1 {
// init
if len(it.bucketIds) == 0 {
return false
}
it.valIdx = 0
it.bucketIdx = 0
return true
}
it.valIdx++
if it.valIdx >= len(it.currentBucket()) {
it.valIdx = 0
it.bucketIdx++
}
return it.bucketIdx < len(it.bucketIds)
}
func (it *Iterator) currentBucket() []interface{} {
return it.vals[it.bucketIds[it.bucketIdx]]
}
|