Iterate iterates over the bitmap, calling the given callback with each value in the bitmap. If the callback returns false, the iteration is halted. The iteration results are undefined if the bitmap is modified (e.g., with Add or Remove). There is no guarantee as to what order the values will be ite
(cb func(x uint32) bool)
| 973 | // The iteration results are undefined if the bitmap is modified (e.g., with Add or Remove). |
| 974 | // There is no guarantee as to what order the values will be iterated. |
| 975 | func (rb *Bitmap) Iterate(cb func(x uint32) bool) { |
| 976 | for i := 0; i < rb.highlowcontainer.size(); i++ { |
| 977 | hs := uint32(rb.highlowcontainer.getKeyAtIndex(i)) << 16 |
| 978 | c := rb.highlowcontainer.getContainerAtIndex(i) |
| 979 | |
| 980 | var shouldContinue bool |
| 981 | // This is hacky but it avoids allocations from invoking an interface method with a closure |
| 982 | switch t := c.(type) { |
| 983 | case *arrayContainer: |
| 984 | shouldContinue = t.iterate(func(x uint16) bool { |
| 985 | return cb(uint32(x) | hs) |
| 986 | }) |
| 987 | case *runContainer16: |
| 988 | shouldContinue = t.iterate(func(x uint16) bool { |
| 989 | return cb(uint32(x) | hs) |
| 990 | }) |
| 991 | case *bitmapContainer: |
| 992 | shouldContinue = t.iterate(func(x uint16) bool { |
| 993 | return cb(uint32(x) | hs) |
| 994 | }) |
| 995 | } |
| 996 | |
| 997 | if !shouldContinue { |
| 998 | break |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | // Iterator creates a new IntPeekable to iterate over the integers contained in the bitmap, in sorted order; |
| 1004 | // the iterator becomes invalid if the bitmap is modified (e.g., with Add or Remove). |