MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _binarySearchLeftmost

Function _binarySearchLeftmost

src/execution_plan/ops/op_value_hash_join.c:34–66  ·  view source on GitHub ↗

performs binary search, returns the leftmost index of a match

Source from the content-addressed store, hash-verified

32
33// performs binary search, returns the leftmost index of a match
34static bool _binarySearchLeftmost
35(
36 uint *idx,
37 Record *array,
38 uint array_len,
39 int join_key_idx,
40 SIValue v
41) {
42 ASSERT(idx != NULL);
43
44 SIValue x;
45 uint pos = 0;
46 uint left = 0;
47 uint right = array_len;
48
49 while(left < right) {
50 pos = (right + left) / 2;
51 x = Record_Get(array[pos], join_key_idx);
52 if(SIValue_Compare(x, v, NULL) < 0) left = pos + 1;
53 else right = pos;
54 }
55
56 // make sure value was found
57 *idx = left;
58
59 if(left == array_len) return false;
60
61 x = Record_Get(array[*idx], join_key_idx);
62 // return false if the value wasn't found or evaluated to NULL
63 int disjointOrNull = 0;
64 return (SIValue_Compare(x, v, &disjointOrNull) == 0 &&
65 disjointOrNull != COMPARED_NULL);
66}
67
68// performs binary search, returns the rightmost index of a match
69// assuming 'v' exists in 'array'

Callers 1

_set_intersection_idxFunction · 0.85

Calls 2

Record_GetFunction · 0.85
SIValue_CompareFunction · 0.85

Tested by

no test coverage detected