MCPcopy
hub / github.com/uber/aresdb / LowerBound

Method LowerBound

memstore/vectors/vector.go:214–231  ·  view source on GitHub ↗

LowerBound returns the index of the first element in vector[first, last) that is greater or equal to the given value. The result is only valid if vector[first, last) is fully sorted in ascendant order. If all values in the given range is less than the given value, LowerBound returns last. Note that

(first int, last int, value unsafe.Pointer)

Source from the content-addressed store, hash-verified

212// returns last.
213// Note that first/last is not checked against vector bound.
214func (v *Vector) LowerBound(first int, last int, value unsafe.Pointer) int {
215 for first < last {
216 mid := (last + first) / 2
217 cmpRes := 0
218 if v.DataType == common.Bool {
219 cmpRes = common.CompareBool(v.GetBool(mid), *(*uint32)(value) != 0)
220 } else {
221 cmpRes = v.CmpFunc(v.GetValue(mid), value)
222 }
223
224 if cmpRes >= 0 {
225 last = mid
226 } else {
227 first = mid + 1
228 }
229 }
230 return first
231}
232
233// UpperBound returns the index of the first element in vector[first, last) that is greater than the
234// given value. The result is only valid if vector[first, last) is fully sorted in ascendant

Callers 4

SliceMethod · 0.80
SliceByValueMethod · 0.80
SliceIndexMethod · 0.80
vector_test.goFile · 0.80

Calls 3

GetBoolMethod · 0.95
GetValueMethod · 0.95
CompareBoolFunction · 0.92

Tested by

no test coverage detected