RemoveRange removes the integers in [rangeStart, rangeEnd) from 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)
| 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 |
| 2046 | // while uint64(0x100000000) cannot be represented as a 32-bit value. |
| 2047 | func (rb *Bitmap) RemoveRange(rangeStart, rangeEnd uint64) { |
| 2048 | if rangeStart >= rangeEnd { |
| 2049 | return |
| 2050 | } |
| 2051 | if rangeEnd-1 > MaxUint32 { |
| 2052 | // logically, we should assume that the user wants to |
| 2053 | // remove all values from rangeStart to infinity |
| 2054 | // see https://github.com/RoaringBitmap/roaring/issues/141 |
| 2055 | rangeEnd = uint64(0x100000000) |
| 2056 | } |
| 2057 | hbStart := uint32(highbits(uint32(rangeStart))) |
| 2058 | lbStart := uint32(lowbits(uint32(rangeStart))) |
| 2059 | hbLast := uint32(highbits(uint32(rangeEnd - 1))) |
| 2060 | lbLast := uint32(lowbits(uint32(rangeEnd - 1))) |
| 2061 | |
| 2062 | var max uint32 = maxLowBit |
| 2063 | |
| 2064 | if hbStart == hbLast { |
| 2065 | i := rb.highlowcontainer.getIndex(uint16(hbStart)) |
| 2066 | if i < 0 { |
| 2067 | return |
| 2068 | } |
| 2069 | c := rb.highlowcontainer.getWritableContainerAtIndex(i).iremoveRange(int(lbStart), int(lbLast+1)) |
| 2070 | if !c.isEmpty() { |
| 2071 | rb.highlowcontainer.setContainerAtIndex(i, c) |
| 2072 | } else { |
| 2073 | rb.highlowcontainer.removeAtIndex(i) |
| 2074 | } |
| 2075 | return |
| 2076 | } |
| 2077 | ifirst := rb.highlowcontainer.getIndex(uint16(hbStart)) |
| 2078 | ilast := rb.highlowcontainer.getIndex(uint16(hbLast)) |
| 2079 | |
| 2080 | if ifirst >= 0 { |
| 2081 | if lbStart != 0 { |
| 2082 | c := rb.highlowcontainer.getWritableContainerAtIndex(ifirst).iremoveRange(int(lbStart), int(max+1)) |
| 2083 | if !c.isEmpty() { |
| 2084 | rb.highlowcontainer.setContainerAtIndex(ifirst, c) |
| 2085 | ifirst++ |
| 2086 | } |
| 2087 | } |
| 2088 | } else { |
| 2089 | ifirst = -ifirst - 1 |
| 2090 | } |
| 2091 | if ilast >= 0 { |
| 2092 | if lbLast != max { |
| 2093 | c := rb.highlowcontainer.getWritableContainerAtIndex(ilast).iremoveRange(int(0), int(lbLast+1)) |
| 2094 | if !c.isEmpty() { |
| 2095 | rb.highlowcontainer.setContainerAtIndex(ilast, c) |
| 2096 | } else { |
| 2097 | ilast++ |
| 2098 | } |
| 2099 | } else { |
| 2100 | ilast++ |
| 2101 | } |
| 2102 | } else { |
| 2103 | ilast = -ilast - 1 |
| 2104 | } |