MCPcopy Create free account
hub / github.com/RoaringBitmap/roaring / RemoveRange

Method RemoveRange

roaring64/roaring64.go:1079–1130  ·  view source on GitHub ↗

RemoveRange removes the integers in [rangeStart, rangeEnd) from the bitmap.

(rangeStart, rangeEnd uint64)

Source from the content-addressed store, hash-verified

1077
1078// RemoveRange removes the integers in [rangeStart, rangeEnd) from the bitmap.
1079func (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

Callers 7

TestRangeRemovalCOWFunction · 0.95
TestDoubleAddCOWFunction · 0.95
TestRangeRemovalFunction · 0.95
TestDoubleAddFunction · 0.95
TestRoaringRangeEndFunction · 0.45

Calls 7

highbitsFunction · 0.70
lowbitsFunction · 0.70
getIndexMethod · 0.45
IsEmptyMethod · 0.45
removeAtIndexMethod · 0.45
removeIndexRangeMethod · 0.45

Tested by 7

TestRangeRemovalCOWFunction · 0.76
TestDoubleAddCOWFunction · 0.76
TestRangeRemovalFunction · 0.76
TestDoubleAddFunction · 0.76
TestRoaringRangeEndFunction · 0.36