Find the index of the first element from the start of the array that verifies the given condition. The function is applied from the start of the array to the pivot.
(a, fn)
| 215 | |
| 216 | |
| 217 | def bisect_keep_left(a, fn): |
| 218 | """ |
| 219 | Find the index of the first element from the start of the array that |
| 220 | verifies the given condition. |
| 221 | The function is applied from the start of the array to the pivot. |
| 222 | """ |
| 223 | lo = 0 |
| 224 | hi = len(a) |
| 225 | while lo < hi: |
| 226 | mid = (lo + hi) // 2 |
| 227 | if fn(a[: mid + 1]): |
| 228 | hi = mid |
| 229 | else: |
| 230 | lo = mid + 1 |
| 231 | return lo |
| 232 | |
| 233 | |
| 234 | def bisect_keep_right(a, fn): |
no outgoing calls