<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">On Thu, Apr 25, 2024 at 2:09 PM Pavel Rappo <<a href="mailto:pavel.rappo@oracle.com">pavel.rappo@oracle.com</a>> wrote:</span><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> On 25 Apr 2024, at 19:41, David Lloyd <<a href="mailto:david.lloyd@redhat.com" target="_blank">david.lloyd@redhat.com</a>> wrote:<br>
> <br>
> The JDK contains a few collection- and array-oriented implementations of binary search. For the most part, they all work the same way: search the target "thing" by index using the obvious bisection strategy, returning either /index/ or /-index-1/ depending on whether it was found at the end of the search.<br>
> <br>
> However, if you're doing a binary search on a thing that is not a list or an array, you have two choices: try to make the thing you're searching on implement List (often infeasible) or write your own binary search.<br>
> <br>
> I'm really tired of writing my own binary search. I've probably done it 50 times by now, each one using a slightly different access and/or compare strategy, and every time is a new chance to typo something or get something backwards, leading to irritating debugging sessions and higher dentist bills.<br>
<br>
Can we safely say that it sets your teeth on edge?<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">You could say that. :)</div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Have a look at this recently filed issue: <a href="https://bugs.openjdk.org/browse/JDK-8326330" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8326330</a></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Oh, nice, I didn't see that come across. It's even more general than my version: I like that. My only complaint is (once again) that the lambda must be capturing in order to work with a plain `IntPredicate`/`LongPredicate`.</div></div><div><br></div></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">- DML • he/him<br></div></div></div>