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

Method iaddRange

arraycontainer.go:106–141  ·  view source on GitHub ↗

add the values in the range [firstOfRange,endx)

(firstOfRange, endx int)

Source from the content-addressed store, hash-verified

104
105// add the values in the range [firstOfRange,endx)
106func (ac *arrayContainer) iaddRange(firstOfRange, endx int) container {
107 if firstOfRange >= endx {
108 return ac
109 }
110 indexstart := binarySearch(ac.content, uint16(firstOfRange))
111 if indexstart < 0 {
112 indexstart = -indexstart - 1
113 }
114 indexend := binarySearch(ac.content, uint16(endx-1))
115 if indexend < 0 {
116 indexend = -indexend - 1
117 } else {
118 indexend++
119 }
120 rangelength := endx - firstOfRange
121 newcardinality := indexstart + (ac.getCardinality() - indexend) + rangelength
122 if newcardinality > arrayDefaultMaxSize {
123 a := ac.toBitmapContainer()
124 return a.iaddRange(firstOfRange, endx)
125 }
126 if cap(ac.content) < newcardinality {
127 tmp := make([]uint16, newcardinality, newcardinality)
128 copy(tmp[:indexstart], ac.content[:indexstart])
129 copy(tmp[indexstart+rangelength:], ac.content[indexend:])
130
131 ac.content = tmp
132 } else {
133 ac.content = ac.content[:newcardinality]
134 copy(ac.content[indexstart+rangelength:], ac.content[indexend:])
135
136 }
137 for k := 0; k < rangelength; k++ {
138 ac.content[k+indexstart] = uint16(firstOfRange + k)
139 }
140 return ac
141}
142
143// remove the values in the range [firstOfRange,endx)
144func (ac *arrayContainer) iremoveRange(firstOfRange, endx int) container {

Callers

nothing calls this directly

Calls 4

getCardinalityMethod · 0.95
toBitmapContainerMethod · 0.95
binarySearchFunction · 0.85
iaddRangeMethod · 0.65

Tested by

no test coverage detected