RemoveRange removes the integers in [rangeStart, rangeEnd) from the bitmap.
(rangeStart, rangeEnd uint64)
| 1077 | |
| 1078 | // RemoveRange removes the integers in [rangeStart, rangeEnd) from the bitmap. |
| 1079 | func (rb *Bitmap) RemoveRange(rangeStart, rangeEnd uint64) { |
| 1080 | if rangeStart >= rangeEnd { |
| 1081 | return |
| 1082 | } |
| 1083 | hbStart := uint64(highbits(rangeStart)) |
| 1084 | lbStart := uint64(lowbits(rangeStart)) |
| 1085 | hbLast := uint64(highbits(rangeEnd - 1)) |
| 1086 | lbLast := uint64(lowbits(rangeEnd - 1)) |
| 1087 | |
| 1088 | var max uint64 = maxLowBit |
| 1089 | |
| 1090 | if hbStart == hbLast { |
| 1091 | i := rb.highlowcontainer.getIndex(uint32(hbStart)) |
| 1092 | if i < 0 { |
| 1093 | return |
| 1094 | } |
| 1095 | c := rb.highlowcontainer.getWritableContainerAtIndex(i) |
| 1096 | c.RemoveRange(lbStart, lbLast+1) |
| 1097 | if c.IsEmpty() { |
| 1098 | rb.highlowcontainer.removeAtIndex(i) |
| 1099 | } |
| 1100 | return |
| 1101 | } |
| 1102 | ifirst := rb.highlowcontainer.getIndex(uint32(hbStart)) |
| 1103 | ilast := rb.highlowcontainer.getIndex(uint32(hbLast)) |
| 1104 | |
| 1105 | if ifirst >= 0 { |
| 1106 | if lbStart != 0 { |
| 1107 | c := rb.highlowcontainer.getWritableContainerAtIndex(ifirst) |
| 1108 | c.RemoveRange(lbStart, max+1) |
| 1109 | if !c.IsEmpty() { |
| 1110 | ifirst++ |
| 1111 | } |
| 1112 | } |
| 1113 | } else { |
| 1114 | ifirst = -ifirst - 1 |
| 1115 | } |
| 1116 | if ilast >= 0 { |
| 1117 | if lbLast != max { |
| 1118 | c := rb.highlowcontainer.getWritableContainerAtIndex(ilast) |
| 1119 | c.RemoveRange(0, lbLast+1) |
| 1120 | if c.IsEmpty() { |
| 1121 | ilast++ |
| 1122 | } |
| 1123 | } else { |
| 1124 | ilast++ |
| 1125 | } |
| 1126 | } else { |
| 1127 | ilast = -ilast - 1 |
| 1128 | } |
| 1129 | rb.highlowcontainer.removeIndexRange(ifirst, ilast) |
| 1130 | } |
| 1131 | |
| 1132 | // Flip negates the bits in the given range (i.e., [rangeStart,rangeEnd)), any integer present in this range and in the bitmap is removed, |
| 1133 | // and any integer present in the range and not in the bitmap is added, a new bitmap is returned leaving |