-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is-Sorted Detection and Binary Search #34
base: main
Are you sure you want to change the base?
Conversation
Add method to collections to find the longest prefix that is sorted along a given predicate. Add a variant method that checks for strictly increasing prefixes. Add overloads to both that default the predicate to the less-than operator.
Add methods to collections to perform binary searches. All the methods assume the collection is sorted along the given predicate, or simply in non-decreasing order for the overloads that default the predicate to the standard less-than operator. The variants return: the quickest match, the earliest match, one past the latest match, and the index range for all matches.
When first creating the pull request, I'm not sure what the "please add |
Add method to collections to find the longest prefix that maintains the same value according to a given predicate Add overload that defaults the predicate to the eqaulity operator.
Thanks for this contribution, @CTMacUser! I don't think these additions rise to the level of utility that would warrant inclusion in the In addition, the APIs in this and the related #37 and #38 interact with some design questions that are still pretty open, in particular around the sortedness of collections (e.g. do we want to add a |
The referenced method works with a two-partition binary search, while my design uses a three-partition binary search. The reference method assumes the collection is divided into doesn't-match and does-match and then searches for the border element. The design I used assumes the collection is divided into less-than, equivalent-to, and greater-than, and then searches for any equivalent element. I require two comparisons per round instead of one, but makes up for it by stopping at the first match instead of continuing to find the border. They're not quite the same thing. |
I added methods to check where a
Collection
stops being sorted, which forms a basis to check if an entire collection is sorted.I added methods to perform a binary search on an already-sorted
Collection
. The general version returns a matching range. The search is performed in several phases, and so those phases are separated into distinct methods.Checklist