Add `SortedArray`, `SortedSet` and `SortedDictionary` with binary search

A bit off-topic, but I looked at the implementation of that and noticed the bidirectional version of partition has two open-coded loops reimplementing firstIndex(where:) and lastIndex(where:) back-to-back.

Digging deeper, I found that the standard-library implementation does the exact same thing.

It seems rather antithetical to the goal of “use the standard algorithms that are already written” when both the standard library and the Algorithms package choose to spend a dozen lines reimplementing something twice (with complicated nested loops whose exit conditions are hidden in the middle, no less!), that would be easy one-liners using the standard index-finding methods.

1 Like