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

Method AddRange

roaring.go:2009–2042  ·  view source on GitHub ↗

AddRange adds the integers in [rangeStart, rangeEnd) to the bitmap. The function uses 64-bit parameters even though a Bitmap stores 32-bit values because it is allowed and meaningful to use [0,uint64(0x100000000)) as a range while uint64(0x100000000) cannot be represented as a 32-bit value.

(rangeStart, rangeEnd uint64)

Source from the content-addressed store, hash-verified

2007// The function uses 64-bit parameters even though a Bitmap stores 32-bit values because it is allowed and meaningful to use [0,uint64(0x100000000)) as a range
2008// while uint64(0x100000000) cannot be represented as a 32-bit value.
2009func (rb *Bitmap) AddRange(rangeStart, rangeEnd uint64) {
2010 if rangeStart >= rangeEnd {
2011 return
2012 }
2013 if rangeEnd-1 > MaxUint32 {
2014 panic("rangeEnd-1 > MaxUint32")
2015 }
2016 hbStart := uint32(highbits(uint32(rangeStart)))
2017 lbStart := uint32(lowbits(uint32(rangeStart)))
2018 hbLast := uint32(highbits(uint32(rangeEnd - 1)))
2019 lbLast := uint32(lowbits(uint32(rangeEnd - 1)))
2020
2021 var max uint32 = maxLowBit
2022 for hb := hbStart; hb <= hbLast; hb++ {
2023 containerStart := uint32(0)
2024 if hb == hbStart {
2025 containerStart = lbStart
2026 }
2027 containerLast := max
2028 if hb == hbLast {
2029 containerLast = lbLast
2030 }
2031
2032 i := rb.highlowcontainer.getIndex(uint16(hb))
2033
2034 if i >= 0 {
2035 c := rb.highlowcontainer.getWritableContainerAtIndex(i).iaddRange(int(containerStart), int(containerLast)+1)
2036 rb.highlowcontainer.setContainerAtIndex(i, c)
2037 } else { // *think* the range of ones must never be
2038 // empty.
2039 rb.highlowcontainer.insertNewKeyValueAt(-i-1, uint16(hb), rangeOfOnes(int(containerStart), int(containerLast)))
2040 }
2041 }
2042}
2043
2044// RemoveRange removes the integers in [rangeStart, rangeEnd) from the bitmap.
2045// The function uses 64-bit parameters even though a Bitmap stores 32-bit values because it is allowed and meaningful to use [0,uint64(0x100000000)) as a range

Callers 15

TestFastCardCOWFunction · 0.95
TestIntersects1COWFunction · 0.95
TestRangePanicCOWFunction · 0.95
TestRangeRemovalCOWFunction · 0.95
TestDoubleAddCOWFunction · 0.95
TestCloneCOWContainersFunction · 0.95
TestInPlaceCOWContainersFunction · 0.95
hashTestFunction · 0.95
TestFastCardFunction · 0.95
TestFastCardUnequalKeysFunction · 0.95
TestIntersects1Function · 0.95

Calls 8

rangeOfOnesFunction · 0.85
highbitsFunction · 0.70
lowbitsFunction · 0.70
iaddRangeMethod · 0.65
getIndexMethod · 0.45
setContainerAtIndexMethod · 0.45
insertNewKeyValueAtMethod · 0.45

Tested by 15

TestFastCardCOWFunction · 0.76
TestIntersects1COWFunction · 0.76
TestRangePanicCOWFunction · 0.76
TestRangeRemovalCOWFunction · 0.76
TestDoubleAddCOWFunction · 0.76
TestCloneCOWContainersFunction · 0.76
TestInPlaceCOWContainersFunction · 0.76
hashTestFunction · 0.76
TestFastCardFunction · 0.76
TestFastCardUnequalKeysFunction · 0.76
TestIntersects1Function · 0.76