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

Method binarySearch

roaringarray.go:421–447  ·  view source on GitHub ↗

binarySearch returns the index of the key. negative value returned if not found

(begin, end int64, ikey uint16)

Source from the content-addressed store, hash-verified

419// binarySearch returns the index of the key.
420// negative value returned if not found
421func (ra *roaringArray) binarySearch(begin, end int64, ikey uint16) int {
422 // TODO: add unit tests
423 low := begin
424 high := end - 1
425 for low+16 <= high {
426 middleIndex := low + (high-low)/2 // avoid overflow
427 middleValue := ra.keys[middleIndex]
428
429 if middleValue < ikey {
430 low = middleIndex + 1
431 } else if middleValue > ikey {
432 high = middleIndex - 1
433 } else {
434 return int(middleIndex)
435 }
436 }
437 for ; low <= high; low++ {
438 val := ra.keys[low]
439 if val >= ikey {
440 if val == ikey {
441 return int(low)
442 }
443 break
444 }
445 }
446 return -int(low + 1)
447}
448
449func (ra *roaringArray) equals(o interface{}) bool {
450 srb, ok := o.(roaringArray)

Callers 3

getContainerMethod · 0.95
getIndexMethod · 0.95
removeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected