MCPcopy Index your code
hub / github.com/questdb/questdb / binarySearch

Method binarySearch

core/src/main/java/io/questdb/std/DoubleList.java:79–107  ·  view source on GitHub ↗
(double value, int scanDir)

Source from the content-addressed store, hash-verified

77 }
78
79 public int binarySearch(double value, int scanDir) {
80
81 // this is the same algorithm as implemented in C (util.h)
82 // template<class T, class V>
83 // inline int64_t binary_search(T *data, V value, int64_t low, int64_t high, int32_t scan_dir)
84 // please ensure these implementations are in sync
85
86 int low = 0;
87 int high = pos - 1;
88 while (high - low > 65) {
89 final int mid = (low + high) >>> 1;
90 final double midVal = data[mid];
91 int cmp = Numbers.compare(midVal, value);
92
93 if (cmp < 0) {
94 low = mid;
95 } else if (cmp > 0) {
96 high = mid - 1;
97 } else {
98 // In case of multiple equal values, find the first
99 return scanDir == Vect.BIN_SEARCH_SCAN_UP ?
100 scrollUp(mid, midVal) :
101 scrollDown(mid, high, midVal);
102 }
103 }
104 return scanDir == Vect.BIN_SEARCH_SCAN_UP ?
105 scanUp(value, low, high + 1) :
106 scanDown(value, low, high + 1);
107 }
108
109 public void checkCapacity(int capacity) {
110 if (capacity < 0) {

Callers 3

testBinarySearch1Method · 0.95
testBinarySearch2Method · 0.95
testBinarySearch3Method · 0.95

Calls 5

compareMethod · 0.95
scrollUpMethod · 0.95
scrollDownMethod · 0.95
scanUpMethod · 0.95
scanDownMethod · 0.95

Tested by 3

testBinarySearch1Method · 0.76
testBinarySearch2Method · 0.76
testBinarySearch3Method · 0.76