lockstep alternative for StoppingPolicy.longest

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Sep 17 15:51:15 PDT 2012


On 9/18/12, Ali Çehreli <acehreli at yahoo.com> wrote:
> I think you actually want .shortest, no?

No I want to continue iterating as long as one of the ranges is still
not empty. I'm not doing just comparisons, once there's only one range
that's not empty I have to do some special checks on its elements. In
simple terms:

void main()
{
    enum sentinel = -1;

    // imagine 3rd element missing and lockstep replaces it with -1
    int[] arr1 = [2, 4, -1];
    int[] arr2 = [2, 4, 3];

    bool state;
    foreach (aa, bb; lockstep(arr1, arr2))
    {
        if (aa == sentinel)
        {
            if (aa % 2 == 0)
            {
                state = true;
                break;
            }
        }
        else
        if (bb == sentinel)
        {
            if (bb % 2 == 0)
            {
                state = true;
                break;
            }
        }
        else
        {
            if (aa == bb)
            {
                state = true;
                break;
            }
        }

    }
}

That's not the algorithm I'm using and I'm not dealing with integers
but that's just an example. If either range is empty I want to
continue doing some special work on the range that isn't empty,
otherwise I have to do work on both.


More information about the Digitalmars-d-learn mailing list