SearchSorted searches the tuple for the target Datum, returning an int with the same contract as sort.Search and a boolean flag signifying whether the datum was found. It assumes that the DTuple is sorted and panics if it is not. The target Datum cannot be NULL or a DTuple that contains NULLs (we c
(ctx *EvalContext, target Datum)
| 3154 | // binary search in this case; for example `(1, NULL) IN ((1, 2), ..)` needs to |
| 3155 | // be |
| 3156 | func (d *DTuple) SearchSorted(ctx *EvalContext, target Datum) (int, bool) { |
| 3157 | d.AssertSorted() |
| 3158 | if target == DNull { |
| 3159 | panic(errors.AssertionFailedf("NULL target (d: %s)", d)) |
| 3160 | } |
| 3161 | if t, ok := target.(*DTuple); ok && t.ContainsNull() { |
| 3162 | panic(errors.AssertionFailedf("target containing NULLs: %#v (d: %s)", target, d)) |
| 3163 | } |
| 3164 | i := sort.Search(len(d.D), func(i int) bool { |
| 3165 | return d.D[i].Compare(ctx, target) >= 0 |
| 3166 | }) |
| 3167 | found := i < len(d.D) && d.D[i].Compare(ctx, target) == 0 |
| 3168 | return i, found |
| 3169 | } |
| 3170 | |
| 3171 | // Normalize sorts and uniques the datum tuple. |
| 3172 | func (d *DTuple) Normalize(ctx *EvalContext) { |
no test coverage detected