mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 01:26:43 +00:00
37 lines
609 B
Go
37 lines
609 B
Go
![]() |
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]]
|
||
|
}
|