RFC on range design for D2
Sergey Gromov
snake.scaly at gmail.com
Wed Sep 10 15:28:33 PDT 2008
Sean Kelly <sean at invisibleduck.org> wrote:
> Sergey Gromov wrote:
> >
> > Now the same algorithm in ranges:
> >
> >> Merge_backward(R1, R2, R3)(R1 s1, R2 s2, R3 dst)
> >> {
> >> for (;;)
> >> {
> >> if (s1.isEmpty())
> >> dst[] = s2[];
> >> else if (s2.isEmpty())
> >> dst[] = s1[];
>
> I'm not sure the above is correct. It should return after the copy is
> performed, and the code also assumes that the size of dst is equal to
> the size of s2 and s1, respectively.
Of course there should be return statements, thank you. I've never
tested this code (obviously), just've thrown it together, so there ought
to be stupid mistakes like this.
As to the destination size. This is merge sort. The size of
destination buffer must be the sum of the sizes of source buffers. As
soon as one of the source buffers is empty, i.e. completely moved to the
destination, there must be place exactly for what left in another source
buffer. If this condition doesn't hold then the arguments weren't
correct in the first place.
More information about the Digitalmars-d-announce
mailing list