MCPcopy
hub / github.com/RoaringBitmap/roaring / Iterate

Method Iterate

roaring.go:975–1001  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
975func (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).

Callers 6

TestIterateFunction · 0.95
TestIterateCompressedFunction · 0.95
TestIterateLargeValuesFunction · 0.95
TestIterateHaltFunction · 0.95
BenchmarkIterateRoaringFunction · 0.95
TestToDenseFunction · 0.80

Calls 4

iterateMethod · 0.65
sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerAtIndexMethod · 0.45

Tested by 6

TestIterateFunction · 0.76
TestIterateCompressedFunction · 0.76
TestIterateLargeValuesFunction · 0.76
TestIterateHaltFunction · 0.76
BenchmarkIterateRoaringFunction · 0.76
TestToDenseFunction · 0.64