| ... | @@ -678,18 +678,23 @@ pub fn partitionPoint( | ... | @@ -678,18 +678,23 @@ pub fn partitionPoint( |
| 678 | context: anytype, | 678 | context: anytype, |
| 679 | comptime predicate: fn (@TypeOf(context), T) bool, | 679 | comptime predicate: fn (@TypeOf(context), T) bool, |
| 680 | ) usize { | 680 | ) usize { |
| 681 | var low: usize = 0; | 681 | var it: usize = 0; |
| 682 | var high: usize = items.len; | 682 | var len: usize = items.len; |
| 683 | | 683 | |
| 684 | while (low < high) { | 684 | while (len > 1) { |
| 685 | const mid = low + (high - low) / 2; | 685 | const half: usize = len / 2; |
| 686 | if (predicate(context, items[mid])) { | 686 | len -= half; |
| 687 | low = mid + 1; | 687 | if (predicate(context, items[it + half - 1])) { |
| 688 | } else { | 688 | @branchHint(.unpredictable); |
| 689 | high = mid; | 689 | it += half; |
| 690 | } | 690 | } |
| 691 | } | 691 | } |
| 692 | return low; | 692 | |
| | 693 | if (it < items.len) { |
| | 694 | it += @intFromBool(predicate(context, items[it])); |
| | 695 | } |
| | 696 | |
| | 697 | return it; |
| 693 | } | 698 | } |
| 694 | | 699 | |
| 695 | test partitionPoint { | 700 | test partitionPoint { |