Transpiled version (2723L) is out of date.
1 | // finds highest index where predicate is true. |
2 | // returns from-1 when predicate is false on whole range. |
3 | // Predicate operates on a range and returns true |
4 | // iff any value in the range is contained in the set. |
5 | static <A> int lastIndexOfRangePredicate(int from default 0, int to, IF2<Int, Int, Bool> pred) {
|
6 | // interval empty? |
7 | if (from >= to) ret from-1; |
8 | |
9 | // predicate false on whole range? |
10 | if (!pred.get(from, to)) ret from-1; |
11 | |
12 | while ping (to-from > 1) {
|
13 | // predicate is true somewhere in range. split in middle. |
14 | int mid = (from + to) >>> 1; |
15 | |
16 | // check higher half |
17 | if (pred.get(mid, to)) |
18 | // predicate is true in higher half. move there. |
19 | from = mid; |
20 | else |
21 | // higher half is clean, move to lower half |
22 | to = mid; |
23 | } |
24 | |
25 | // we've narrowed things down to at most one element, return index |
26 | ret to-1; |
27 | } |
Began life as a copy of #1030504
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1030507 |
| Snippet name: | lastIndexOfRangePredicate |
| Eternal ID of this version: | #1030507/9 |
| Text MD5: | 01c819d9cdfa1164630eb29cba5dd577 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-01-03 22:34:23 |
| Source code size: | 883 bytes / 27 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 449 / 571 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |