MCPcopy Index your code
hub / github.com/RoaringBitmap/roaring / notClose

Method notClose

arraycontainer.go:174–223  ·  view source on GitHub ↗

flip the values in the range [firstOfRange,lastOfRange]

(firstOfRange, lastOfRange int)

Source from the content-addressed store, hash-verified

172
173// flip the values in the range [firstOfRange,lastOfRange]
174func (ac *arrayContainer) notClose(firstOfRange, lastOfRange int) container {
175 if firstOfRange > lastOfRange { // unlike add and remove, not uses an inclusive range [firstOfRange,lastOfRange]
176 return ac.clone()
177 }
178
179 // determine the span of array indices to be affected^M
180 startIndex := binarySearch(ac.content, uint16(firstOfRange))
181 if startIndex < 0 {
182 startIndex = -startIndex - 1
183 }
184 lastIndex := binarySearch(ac.content, uint16(lastOfRange))
185 if lastIndex < 0 {
186 lastIndex = -lastIndex - 2
187 }
188 currentValuesInRange := lastIndex - startIndex + 1
189 spanToBeFlipped := lastOfRange - firstOfRange + 1
190 newValuesInRange := spanToBeFlipped - currentValuesInRange
191 cardinalityChange := newValuesInRange - currentValuesInRange
192 newCardinality := len(ac.content) + cardinalityChange
193 if newCardinality > arrayDefaultMaxSize {
194 return ac.toBitmapContainer().not(firstOfRange, lastOfRange+1)
195 }
196 answer := newArrayContainer()
197 answer.content = make([]uint16, newCardinality, newCardinality) // a hack for sure
198
199 copy(answer.content, ac.content[:startIndex])
200 outPos := startIndex
201 inPos := startIndex
202 valInRange := firstOfRange
203 for ; valInRange <= lastOfRange && inPos <= lastIndex; valInRange++ {
204 if uint16(valInRange) != ac.content[inPos] {
205 answer.content[outPos] = uint16(valInRange)
206 outPos++
207 } else {
208 inPos++
209 }
210 }
211
212 for ; valInRange <= lastOfRange; valInRange++ {
213 answer.content[outPos] = uint16(valInRange)
214 outPos++
215 }
216
217 for i := lastIndex + 1; i < len(ac.content); i++ {
218 answer.content[outPos] = ac.content[i]
219 outPos++
220 }
221 answer.content = answer.content[:newCardinality]
222 return answer
223}
224
225func (ac *arrayContainer) equals(o container) bool {
226 srb, ok := o.(*arrayContainer)

Callers 3

notMethod · 0.95
TestArrayContainerEtc070Function · 0.80

Calls 5

cloneMethod · 0.95
toBitmapContainerMethod · 0.95
binarySearchFunction · 0.85
newArrayContainerFunction · 0.85
notMethod · 0.65

Tested by 2

TestArrayContainerEtc070Function · 0.64