look up first intersecting cached record CR position returns false if no intersecting record is found
| 115 | // look up first intersecting cached record CR position |
| 116 | // returns false if no intersecting record is found |
| 117 | static bool _set_intersection_idx |
| 118 | ( |
| 119 | OpValueHashJoin *op, |
| 120 | SIValue v |
| 121 | ) { |
| 122 | op->intersect_idx = -1; |
| 123 | op->number_of_intersections = 0; |
| 124 | uint record_count = array_len(op->cached_records); |
| 125 | |
| 126 | uint leftmost_idx = 0; |
| 127 | uint rightmost_idx = 0; |
| 128 | |
| 129 | if(!_binarySearchLeftmost(&leftmost_idx, op->cached_records, |
| 130 | array_len(op->cached_records), op->join_value_rec_idx, v)) { |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | // value was found |
| 135 | // idx points to the first intersecting record |
| 136 | // update number_of_intersections to count how many |
| 137 | // records share the same value |
| 138 | op->intersect_idx = leftmost_idx; |
| 139 | |
| 140 | // count how many records share the same node |
| 141 | // reduce search space by truncating left bound |
| 142 | bool found = _binarySearchRightmost(&rightmost_idx, |
| 143 | op->cached_records + leftmost_idx, record_count - leftmost_idx, |
| 144 | op->join_value_rec_idx, v); |
| 145 | UNUSED(found); |
| 146 | ASSERT(found == true); |
| 147 | |
| 148 | // compensate index |
| 149 | rightmost_idx += leftmost_idx; |
| 150 | // +1 consider rightmost_idx == leftmost_idx |
| 151 | op->number_of_intersections = rightmost_idx - leftmost_idx + 1; |
| 152 | ASSERT(op->number_of_intersections > 0); |
| 153 | |
| 154 | return true; |
| 155 | } |
| 156 | |
| 157 | // sorts cached records by joined value |
| 158 | void _sort_cached_records |
no test coverage detected