Re: range->vector Wolfgang Corcoran-Mathe 03 Sep 2020 07:11 UTC

On 2020-09-02 23:35 -0400, John Cowan wrote:
> Range-reverse is safe unless you reverse the range over and over (which is
> unlikely), because the reverser part is trivially O(1).

OK.

A thought: What do you think about keeping the indexer-composing
version in the two-range case of range-append?  e.g.

    (define range-append
      (case-lambda
       ; ...
       ((ra rb)                            ; two-range fast path
        (let ((la (range-length ra))
              (lb (range-length rb)))
          (raw-range 0
                     (+ la lb)
                     (lambda (i)
                       (if (< i la)
                           (range-ref ra i)
                           (range-ref rb (- i la)))))))
       ; ...
       ))

This indexer is O(1) on its own, and successive two-range appends
would, in essence, build a binary search tree associating indices with
ranges.

The variadic case would still return a vector-style range.

--
Wolfgang Corcoran-Mathe  <xxxxxx@sigwinch.xyz>

"The usual way in which we plan today for tomorrow is in
yesterday's vocabulary." --Edsger W. Dijkstra