lorenzoracca / Swift-binary-search

Binary search imply that will presented as proposal to swift-evolution
2 stars 2 forks source link

Add equalRange method #7

Closed natecook1000 closed 8 years ago

natecook1000 commented 8 years ago

This adds the two variations of the equalRange method and fixes a few issues with the existing code. The methods are now marked public, so you can drop this in a Playground's Sources directory and test the methods there.

The extension constraints for the equalRange method are ugly because it calls the other methods on its subsequences—those extra bits are essentially the definition of a subsequence, but the compiler can't require them without all that extra stuff.

I don't particularly like the equalRange name—I know it's what C++ calls that algorithm but it doesn't describe it very well. What do you all think of range(of:) or bounds(of:) to match lower/upperBound?