aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty/cty/set/iterator.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/set/iterator.go')
-rw-r--r--vendor/github.com/zclconf/go-cty/cty/set/iterator.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/set/iterator.go b/vendor/github.com/zclconf/go-cty/cty/set/iterator.go
new file mode 100644
index 0000000..f15498e
--- /dev/null
+++ b/vendor/github.com/zclconf/go-cty/cty/set/iterator.go
@@ -0,0 +1,36 @@
1package set
2
3type Iterator struct {
4 bucketIds []int
5 vals map[int][]interface{}
6 bucketIdx int
7 valIdx int
8}
9
10func (it *Iterator) Value() interface{} {
11 return it.currentBucket()[it.valIdx]
12}
13
14func (it *Iterator) Next() bool {
15 if it.bucketIdx == -1 {
16 // init
17 if len(it.bucketIds) == 0 {
18 return false
19 }
20
21 it.valIdx = 0
22 it.bucketIdx = 0
23 return true
24 }
25
26 it.valIdx++
27 if it.valIdx >= len(it.currentBucket()) {
28 it.valIdx = 0
29 it.bucketIdx++
30 }
31 return it.bucketIdx < len(it.bucketIds)
32}
33
34func (it *Iterator) currentBucket() []interface{} {
35 return it.vals[it.bucketIds[it.bucketIdx]]
36}