Changeset 15293
- Timestamp:
- Oct 11, 2007, 3:50:04 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pztool.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r15234 r15293 40 40 static bool copydoneCompleteExp(pxConfig *config); 41 41 static psArray *pzGetPendingCameras(pxConfig *config); 42 static psArray *pzArrayZip(psArray *arraySet );42 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); 43 43 44 44 # define MODECASE(caseName, func) \ … … 322 322 psArray *cameraImfiles = psArrayAlloc(0); 323 323 324 // the total number of imfiles retreived so far325 long imfiles = 0;326 // any slots left over by a query returning less than the per camera limit327 long leftOvers = 0;328 324 for (long i = 0; i < psArrayLength(cameras); i++) { 329 325 psString query = pxDataGet("pztool_pendingimfile.sql"); … … 343 339 } 344 340 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" 347 347 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); 371 349 psStringAppend(&query, " %s", limitString); 372 350 psFree(limitString); … … 393 371 } 394 372 395 // if we got less rows then the limit for this camera, give the extra396 // slots to the next camera.397 if (camLimit) {398 leftOvers = camLimit - psArrayLength(result);399 }400 401 // update the total count of imfiles fetched402 imfiles += psArrayLength(result);403 404 373 // add this query into the array of result set 405 374 psArrayAdd(cameraImfiles, 0, result); 406 375 psFree(result); 407 408 // check to see if we've retreived enough imfiles409 if (imfiles >= limit) {410 break;411 }412 376 } 413 377 414 378 // stitch the arrays of imfiles together 415 psArray *output = pzArrayZip(cameraImfiles );379 psArray *output = pzArrayZip(cameraImfiles, limit); 416 380 psFree(cameraImfiles); 417 381 … … 740 704 } 741 705 742 static psArray *pzArrayZip(psArray *arraySet) 743 { 706 static psArray *pzArrayZip(psArray *arraySet, psS64 limit) 707 { 708 // figure out the combined size of all arrays in the set 744 709 long setSize = 0; 745 746 // figure out the size of the combined arrays747 710 for (long i = 0; i < psArrayLength(arraySet); i++) { 748 711 setSize += psArrayLength(arraySet->data[i]); 749 712 } 750 713 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); 752 720 // 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 ) { 759 735 760 736 psArray *array = arraySet->data[i];
Note:
See TracChangeset
for help on using the changeset viewer.
