IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15293


Ignore:
Timestamp:
Oct 11, 2007, 3:50:04 PM (19 years ago)
Author:
jhoblitt
Message:

fix -pendingimfile -limit handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pztool.c

    r15234 r15293  
    4040static bool copydoneCompleteExp(pxConfig *config);
    4141static psArray *pzGetPendingCameras(pxConfig *config);
    42 static psArray *pzArrayZip(psArray *arraySet);
     42static psArray *pzArrayZip(psArray *arraySet, psS64 limit);
    4343
    4444# define MODECASE(caseName, func) \
     
    322322    psArray *cameraImfiles = psArrayAlloc(0);
    323323
    324     // the total number of imfiles retreived so far
    325     long imfiles = 0;
    326     // any slots left over by a query returning less than the per camera limit
    327     long leftOvers = 0;
    328324    for (long i = 0; i < psArrayLength(cameras); i++) {
    329325        psString query = pxDataGet("pztool_pendingimfile.sql");
     
    343339        }
    344340
    345         long camLimit = 0;
    346         // avoid possible div by zero
     341        // request the full "limit" from each known camera and throw away any
     342        // "extra" rows that we may have after merging the results.  This is
     343        // a lot simplier than a complicated scheme (tried that) to attempt to
     344        // request on the right number of rows for each camera
     345       
     346        // treat limit == 0 as "no limit"
    347347        if (limit) {
    348             // in the case where the limit asked for is less then the number of
    349             // cameras we have, return 1 imfile per camera and we'll stop
    350             // making per camera queries when we have reached limit.
    351             if (limit < psArrayLength(cameras)) {
    352                 camLimit = 1;
    353             } else {
    354                 camLimit = limit / psArrayLength(cameras);
    355                 // add the modulous to the first camera in the list, so if
    356                 // limit is not even divsable by the number of cameras, the
    357                 // left overs don't get dropped on the floor
    358                 if (i == 0) {
    359                     camLimit += limit % psArrayLength(cameras);
    360                 }
    361             }
    362         }
    363 
    364         // treat limit == 0 as "no limit"
    365         if (camLimit) {
    366             // pickup the left overs from the prevous camera
    367             camLimit += leftOvers;
    368 
    369             // divide limit by the number of cameras
    370             psString limitString = psDBGenerateLimitSQL(camLimit);
     348            psString limitString = psDBGenerateLimitSQL(limit);
    371349            psStringAppend(&query, " %s", limitString);
    372350            psFree(limitString);
     
    393371        }
    394372
    395         // if we got less rows then the limit for this camera, give the extra
    396         // slots to the next camera.
    397         if (camLimit) {
    398             leftOvers = camLimit - psArrayLength(result);
    399         }
    400 
    401         // update the total count of imfiles fetched
    402         imfiles += psArrayLength(result);
    403 
    404373        // add this query into the array of result set
    405374        psArrayAdd(cameraImfiles, 0, result);
    406375        psFree(result);
    407 
    408         // check to see if we've retreived enough imfiles
    409         if (imfiles >= limit) {
    410             break;
    411         }
    412376    }
    413377
    414378    // stitch the arrays of imfiles together
    415     psArray *output = pzArrayZip(cameraImfiles);
     379    psArray *output = pzArrayZip(cameraImfiles, limit);
    416380    psFree(cameraImfiles);
    417381
     
    740704}
    741705
    742 static psArray *pzArrayZip(psArray *arraySet)
    743 {
     706static psArray *pzArrayZip(psArray *arraySet, psS64 limit)
     707{
     708    // figure out the combined size of all arrays in the set
    744709    long setSize = 0;
    745 
    746     // figure out the size of the combined arrays
    747710    for (long i = 0; i < psArrayLength(arraySet); i++) {
    748711        setSize += psArrayLength(arraySet->data[i]);
    749712    }
    750713
    751     psArray *output = psArrayAllocEmpty(setSize);
     714    // treat 0 as "no limit"
     715    if (limit == 0) {
     716        limit = setSize;
     717    }
     718
     719    psArray *output = psArrayAllocEmpty(limit);
    752720    // loop over each array in the set forever
    753     long index = 0; // the depth into each array
    754     long counter; // counter - the total number of elements zipped so far
    755     long i; // i - which array in the set
    756     for (counter = 0, i = 0;
    757             (counter < setSize) && (i < psArrayLength(arraySet));
    758             counter++, ++i, i = i % psArrayLength(arraySet), i % psArrayLength(arraySet) ? : ++index) {
     721    for (
     722            // init
     723            long counter = 0,   // the total number of elements zipped so far
     724            i = 0,              // which array in the set
     725            index = 0;          // the depth into each array
     726            // test
     727            (counter < setSize)
     728            && (counter < limit)
     729            && (i < psArrayLength(arraySet));
     730            // incr
     731            counter++, ++i,
     732            i = i % psArrayLength(arraySet),
     733            i % psArrayLength(arraySet) ? : ++index
     734        ) {
    759735
    760736        psArray *array = arraySet->data[i];
Note: See TracChangeset for help on using the changeset viewer.