Re: An attempt to clean up binary search
Daphne Preston-Kendal 11 Nov 2021 20:18 UTC
On 11 Nov 2021, at 20:29, John Cowan <xxxxxx@ccil.org> wrote:
> Currently, binary search is provided over vectors in SRFI 43 and SRFI 133 and over flexvectors in SRFI 214. SRFI 223 provides bisection over arbitrary sorted numerically-indexed sequences, which subsumes binary search but provides both the smallest and the largest index whose value matches the search key rather than any arbitrary matching index. It also specifies procedures for vector bisection that are easier to use than generalized bisection.
>
> I propose the following changes to the four SRFIs by way of implementation changes and post-finalization notes:
>
> 1. The SRFI 223 sample implementation does not define the vector bisection procedures at all, even though they are trivial to provide. This can be fixed silently.
It’s already there:
https://github.com/scheme-requests-for-implementation/srfi-223/blob/master/srfi-223.scm#L35-L36
> 2. Add libraries to the sample implementation for at least bytevectors and flexvectors. It should be very little additional work to add them for the twelve SRFI 160 homogeneous array subtypes; I don't think they make much sense for strings, bitvectors, etc. This should also be doable silently; it's basically 14 tiny .sld files.
>
> 3. Add a PFN to SRFI 223 saying that the sample implementation provides these libraries.
No problem, as long as they’re in sublibraries.
> 4. Add a PFN to the other three SRFIs deprecating their binary-search functions in favor of the corresponding SRFI 223 libraries.
I was thinking this would be done at the R7RS stage (Ultraviolet if necessary), but we can certainly do this now like this, yes.
Note the preference expressed under the ‘Library names’ section of SRFI 223.
Daphne