-
Notifications
You must be signed in to change notification settings - Fork 3
/
intset_iter.go
43 lines (36 loc) · 935 Bytes
/
intset_iter.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
package frozen
// IntLess dictates the order of two elements.
type IntLess func(a, b int) bool
type IntIterator interface {
Next() bool
Value() int
}
type intSetIterator struct {
blockIter *MapIterator
block []cellMask
firstIntInCell int
}
func (i *intSetIterator) Next() bool {
if len(i.block) > 0 && i.block[0] != 0 {
i.block[0] &= i.block[0] - 1
}
if len(i.block) > 0 && i.block[0] == 0 {
for ; len(i.block) != 0 && i.block[0] == 0; i.block = i.block[1:] {
i.firstIntInCell += cellBits
}
}
if len(i.block) == 0 {
if !i.blockIter.Next() {
return false
}
i.firstIntInCell = i.blockIter.Key().(int) * blockBits
block := i.blockIter.Value().(cellBlock)
for i.block = block[:]; i.block[0] == 0; i.block = i.block[1:] {
i.firstIntInCell += cellBits
}
}
return i.block[0] != 0
}
func (i *intSetIterator) Value() int {
return i.firstIntInCell + BitIterator(i.block[0]).Index()
}