int nDataInChannel = 0;
int nDataInChannel = initDataInChannel;
    LatencyEdge(        LatencyNode upstream,        int outputChannel,        LatencyNode downstream,        int inputChannel)    {        // do some trivial initializations        {            src = upstream;            srcChannel = outputChannel;            dst = downstream;            dstChannel = inputChannel;            srcUpstream = true;        }        // now figure out how many times each of the two nodes        // need to run to execute a full steady state execution        // between them        {            BigInteger srcData =                BigInteger.valueOf(src.getSteadyStatePush(srcChannel));            BigInteger dstData =                BigInteger.valueOf(dst.getSteadyStatePop(dstChannel));            BigInteger gcd = srcData.gcd(dstData);            BigInteger steadyStateData =                srcData.multiply(dstData).divide(gcd);            numSteadySrcExec =                dstData.divide(gcd).intValue() * src.getSteadyNumPhases();            numSteadyDstExec =                srcData.divide(gcd).intValue() * dst.getSteadyNumPhases();            // don't initialize (allocate) this array, 'cause I don't yet            // know its size! I'll compute the number of phases requried for            // initialization below, allocate the array, and go through the             // whole dependency (init and steady) at once.        }        // compute the dependency of downstream on upstream        // this takes initialization into account, thus there        // are two stages in the depency: the initialization stage        // and the steady stage.        {            // compute the initialization stage of data dependency.            // do this twice. the first time i'll just record how many            // compute the initialization stage of data dependency            // this is done in two steps (usually only one will be            // required, but I never know which one ahead of time).            // First I'll execute the entire initialization schedule            // of the downstream operator. This will force some of the            // execution of the upstream operator. Then I'll execute            // any remaining phases of the intitialization of the            // upstream operator, while computing which phase of the            // downstream operator depends on the upstream operator.            //            // Do not record the dependency, just figure out how many phases            // are required from the dst node to do it :) The dependncy will            // be recorded later (below) together with the steady state            // dependency in one fell swoop             {                int dstStage = 0, srcStage = 0;                int nDataInChannel = 0;                {                    for (dstStage = 0;                        dstStage < dst.getInitNumPhases();                        dstStage++)                    {                        int dataNeeded =                            dst.getPhasePeek(dstStage, inputChannel);                        while (dataNeeded >= nDataInChannel)                        {                            nDataInChannel                                += src.getPhasePush(srcStage, outputChannel);                            srcStage++;                        }                        nDataInChannel                            -= dst.getPhasePop(dstStage, inputChannel);                    }                }                // the dst has been initialized, now finish initializing                // the src                {                    for (; srcStage < src.getInitNumPhases(); srcStage++)                    {                        nDataInChannel                            += src.getPhasePush(srcStage, outputChannel);                        while (nDataInChannel                            >= dst.getPhasePeek(dstStage, inputChannel))                        {                            nDataInChannel                                -= dst.getPhasePop(dstStage, inputChannel);                            dstStage++;                        }                    }                }                numInitSrcExec = srcStage;                numInitDstExec = dstStage;            }            // allocate storage to keep track of the dependency            dst2srcDependency = new int[numInitDstExec + numSteadyDstExec];            // compute the dependency for numInitDstExec + numSteadyDstExec            // phases of the dst node.            // this will do the initialization. if the src doesn't             // execute enough times that's OK, 'cause its last phases would             // not push any data            {                int dstStage = 0, srcStage = 0;                int nDataInChannel = 0;                for (dstStage = 0;                    dstStage < numInitDstExec + numSteadyDstExec;                    dstStage++)                {                    int dataNeeded =                        dst.getPhasePeek(dstStage, inputChannel);                    while (dataNeeded >= nDataInChannel)                    {                        nDataInChannel                            += src.getPhasePush(srcStage, outputChannel);                        srcStage++;                    }                    dst2srcDependency[dstStage] = srcStage - 1;                    nDataInChannel                        -= dst.getPhasePop(dstStage, inputChannel);                }            }        }    }