| 39 | |
| 40 | template <typename Predicate> |
| 41 | int FindInterval(int size, const Predicate &pred) { |
| 42 | int first = 0, len = size; |
| 43 | while (len > 0) { |
| 44 | int half = len >> 1, middle = first + half; |
| 45 | // Bisect range based on value of _pred_ at _middle_ |
| 46 | if (pred(middle)) { |
| 47 | first = middle + 1; |
| 48 | len -= half + 1; |
| 49 | } else |
| 50 | len = half; |
| 51 | } |
| 52 | return Clamp(first - 1, 0, size - 2); |
| 53 | } |
| 54 | |
| 55 | // Spectrum Method Definitions |
| 56 | bool SpectrumSamplesSorted(const float *lambda, const float *vals, int n) { |
no test coverage detected