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