00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "qset.h"
00015 #include "mem.h"
00016 #include <stdio.h>
00017 #include <string.h>
00018
00019
00020
00021
00022
00023 #ifndef qhDEFlibqhull
00024 typedef struct ridgeT ridgeT;
00025 typedef struct facetT facetT;
00026 void qh_errexit(int exitcode, facetT *, ridgeT *);
00027 void qh_fprintf(FILE *fp, int msgcode, const char *fmt, ... );
00028 # ifdef _MSC_VER
00029 # pragma warning( disable : 4127)
00030 # pragma warning( disable : 4706)
00031 # endif
00032 #endif
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 void qh_setaddnth(setT **setp, int nth, void *newelem) {
00056 int *sizep, oldsize, i;
00057 void **oldp, **newp;
00058
00059 if (!*setp || !*(sizep= SETsizeaddr_(*setp))) {
00060 qh_setlarger(setp);
00061 sizep= SETsizeaddr_(*setp);
00062 }
00063 oldsize= *sizep - 1;
00064 if (nth < 0 || nth > oldsize) {
00065 qh_fprintf(qhmem.ferr, 6171, "qhull internal error (qh_setaddnth): nth %d is out-of-bounds for set:\n", nth);
00066 qh_setprint(qhmem.ferr, "", *setp);
00067 qh_errexit(qhmem_ERRqhull, NULL, NULL);
00068 }
00069 (*sizep)++;
00070 oldp= SETelemaddr_(*setp, oldsize, void);
00071 newp= oldp+1;
00072 for (i=oldsize-nth+1; i--; )
00073 *(newp--)= *(oldp--);
00074 *newp= newelem;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 void qh_setaddsorted(setT **setp, void *newelem) {
00094 int newindex=0;
00095 void *elem, **elemp;
00096
00097 FOREACHelem_(*setp) {
00098 if (elem < newelem)
00099 newindex++;
00100 else if (elem == newelem)
00101 return;
00102 else
00103 break;
00104 }
00105 qh_setaddnth(setp, newindex, newelem);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void qh_setappend(setT **setp, void *newelem) {
00125 int *sizep, end_idx;
00126
00127 if (!newelem)
00128 return;
00129 if (!*setp || !*(sizep= SETsizeaddr_(*setp))) {
00130 qh_setlarger(setp);
00131 sizep= SETsizeaddr_(*setp);
00132 }
00133 end_idx = (*sizep)++ - 1;
00134 (*setp)->e[end_idx].p = newelem;
00135 (*setp)->e[end_idx + 1].p = NULL;
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 void qh_setappend_set(setT **setp, setT *setA) {
00154 int *sizep, sizeA, size;
00155 setT *oldset;
00156
00157 if (!setA)
00158 return;
00159 SETreturnsize_(setA, sizeA);
00160 if (!*setp)
00161 *setp= qh_setnew(sizeA);
00162 sizep= SETsizeaddr_(*setp);
00163 if (!(size= *sizep))
00164 size= (*setp)->maxsize;
00165 else
00166 size--;
00167 if (size + sizeA > (*setp)->maxsize) {
00168 oldset= *setp;
00169 *setp= qh_setcopy(oldset, sizeA);
00170 qh_setfree(&oldset);
00171 sizep= SETsizeaddr_(*setp);
00172 }
00173 *sizep= size+sizeA+1;
00174 if (sizeA > 0)
00175 memcpy((char *)&((*setp)->e[size].p), (char *)&(setA->e[0].p), (size_t)(sizeA+1) * SETelemsize);
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 void qh_setappend2ndlast(setT **setp, void *newelem) {
00196 int *sizep;
00197 void **endp, **lastp;
00198
00199 if (!*setp || !*(sizep= SETsizeaddr_(*setp))) {
00200 qh_setlarger(setp);
00201 sizep= SETsizeaddr_(*setp);
00202 }
00203 endp= SETelemaddr_(*setp, (*sizep)++ -1, void);
00204 lastp= endp-1;
00205 *(endp++)= *lastp;
00206 *endp= NULL;
00207 *lastp= newelem;
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 void qh_setcheck(setT *set, const char *tname, unsigned id) {
00222 int maxsize, size;
00223 int waserr= 0;
00224
00225 if (!set)
00226 return;
00227 SETreturnsize_(set, size);
00228 maxsize= set->maxsize;
00229 if (size > maxsize || !maxsize) {
00230 qh_fprintf(qhmem.ferr, 6172, "qhull internal error (qh_setcheck): actual size %d of %s%d is greater than max size %d\n",
00231 size, tname, id, maxsize);
00232 waserr= 1;
00233 }else if (set->e[size].p) {
00234 qh_fprintf(qhmem.ferr, 6173, "qhull internal error (qh_setcheck): %s%d(size %d max %d) is not null terminated.\n",
00235 tname, id, maxsize, size-1);
00236 waserr= 1;
00237 }
00238 if (waserr) {
00239 qh_setprint(qhmem.ferr, "ERRONEOUS", set);
00240 qh_errexit(qhmem_ERRqhull, NULL, NULL);
00241 }
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 void qh_setcompact(setT *set) {
00264 int size;
00265 void **destp, **elemp, **endp, **firstp;
00266
00267 if (!set)
00268 return;
00269 SETreturnsize_(set, size);
00270 destp= elemp= firstp= SETaddr_(set, void);
00271 endp= destp + size;
00272 while (1) {
00273 if (!(*destp++ = *elemp++)) {
00274 destp--;
00275 if (elemp > endp)
00276 break;
00277 }
00278 }
00279 qh_settruncate(set, (int)(destp-firstp));
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 setT *qh_setcopy(setT *set, int extra) {
00298 setT *newset;
00299 int size;
00300
00301 if (extra < 0)
00302 extra= 0;
00303 SETreturnsize_(set, size);
00304 newset= qh_setnew(size+extra);
00305 *SETsizeaddr_(newset)= size+1;
00306 memcpy((char *)&(newset->e[0].p), (char *)&(set->e[0].p), (size_t)(size+1) * SETelemsize);
00307 return(newset);
00308 }
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 void *qh_setdel(setT *set, void *oldelem) {
00332 void **elemp, **lastp;
00333 int *sizep;
00334
00335 if (!set)
00336 return NULL;
00337 elemp= SETaddr_(set, void);
00338 while (*elemp != oldelem && *elemp)
00339 elemp++;
00340 if (*elemp) {
00341 sizep= SETsizeaddr_(set);
00342 if (!(*sizep)--)
00343 *sizep= set->maxsize;
00344 lastp= SETelemaddr_(set, *sizep-1, void);
00345 *elemp= *lastp;
00346 *lastp= NULL;
00347 return oldelem;
00348 }
00349 return NULL;
00350 }
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 void *qh_setdellast(setT *set) {
00371 int setsize;
00372 int maxsize;
00373 int *sizep;
00374 void *returnvalue;
00375
00376 if (!set || !(set->e[0].p))
00377 return NULL;
00378 sizep= SETsizeaddr_(set);
00379 if ((setsize= *sizep)) {
00380 returnvalue= set->e[setsize - 2].p;
00381 set->e[setsize - 2].p= NULL;
00382 (*sizep)--;
00383 }else {
00384 maxsize= set->maxsize;
00385 returnvalue= set->e[maxsize - 1].p;
00386 set->e[maxsize - 1].p= NULL;
00387 *sizep= maxsize;
00388 }
00389 return returnvalue;
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 void *qh_setdelnth(setT *set, int nth) {
00411 void **elemp, **lastp, *elem;
00412 int *sizep;
00413
00414
00415 elemp= SETelemaddr_(set, nth, void);
00416 sizep= SETsizeaddr_(set);
00417 if (!(*sizep)--)
00418 *sizep= set->maxsize;
00419 if (nth < 0 || nth >= *sizep) {
00420 qh_fprintf(qhmem.ferr, 6174, "qhull internal error (qh_setaddnth): nth %d is out-of-bounds for set:\n", nth);
00421 qh_setprint(qhmem.ferr, "", set);
00422 qh_errexit(qhmem_ERRqhull, NULL, NULL);
00423 }
00424 lastp= SETelemaddr_(set, *sizep-1, void);
00425 elem= *elemp;
00426 *elemp= *lastp;
00427 *lastp= NULL;
00428 return elem;
00429 }
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 void *qh_setdelnthsorted(setT *set, int nth) {
00452 void **newp, **oldp, *elem;
00453 int *sizep;
00454
00455 sizep= SETsizeaddr_(set);
00456 if (nth < 0 || (*sizep && nth >= *sizep-1) || nth >= set->maxsize) {
00457 qh_fprintf(qhmem.ferr, 6175, "qhull internal error (qh_setaddnth): nth %d is out-of-bounds for set:\n", nth);
00458 qh_setprint(qhmem.ferr, "", set);
00459 qh_errexit(qhmem_ERRqhull, NULL, NULL);
00460 }
00461 newp= SETelemaddr_(set, nth, void);
00462 elem= *newp;
00463 oldp= newp+1;
00464 while ((*(newp++)= *(oldp++)))
00465 ;
00466 if (!(*sizep)--)
00467 *sizep= set->maxsize;
00468 return elem;
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 void *qh_setdelsorted(setT *set, void *oldelem) {
00490 void **newp, **oldp;
00491 int *sizep;
00492
00493 if (!set)
00494 return NULL;
00495 newp= SETaddr_(set, void);
00496 while (*newp != oldelem && *newp)
00497 newp++;
00498 if (*newp) {
00499 oldp= newp+1;
00500 while ((*(newp++)= *(oldp++)))
00501 ;
00502 sizep= SETsizeaddr_(set);
00503 if (!(*sizep)--)
00504 *sizep= set->maxsize;
00505 return oldelem;
00506 }
00507 return NULL;
00508 }
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526 setT *qh_setduplicate(setT *set, int elemsize) {
00527 void *elem, **elemp, *newElem;
00528 setT *newSet;
00529 int size;
00530
00531 if (!(size= qh_setsize(set)))
00532 return NULL;
00533 newSet= qh_setnew(size);
00534 FOREACHelem_(set) {
00535 newElem= qh_memalloc(elemsize);
00536 memcpy(newElem, elem, (size_t)elemsize);
00537 qh_setappend(&newSet, newElem);
00538 }
00539 return newSet;
00540 }
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557 int qh_setequal(setT *setA, setT *setB) {
00558 void **elemAp, **elemBp;
00559 int sizeA, sizeB;
00560
00561 SETreturnsize_(setA, sizeA);
00562 SETreturnsize_(setB, sizeB);
00563 if (sizeA != sizeB)
00564 return 0;
00565 if (!sizeA)
00566 return 1;
00567 elemAp= SETaddr_(setA, void);
00568 elemBp= SETaddr_(setB, void);
00569 if (!memcmp((char *)elemAp, (char *)elemBp, sizeA*SETelemsize))
00570 return 1;
00571 return 0;
00572 }
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 int qh_setequal_except(setT *setA, void *skipelemA, setT *setB, void *skipelemB) {
00596 void **elemA, **elemB;
00597 int skip=0;
00598
00599 elemA= SETaddr_(setA, void);
00600 elemB= SETaddr_(setB, void);
00601 while (1) {
00602 if (*elemA == skipelemA) {
00603 skip++;
00604 elemA++;
00605 }
00606 if (skipelemB) {
00607 if (*elemB == skipelemB) {
00608 skip++;
00609 elemB++;
00610 }
00611 }else if (*elemA != *elemB) {
00612 skip++;
00613 if (!(skipelemB= *elemB++))
00614 return 0;
00615 }
00616 if (!*elemA)
00617 break;
00618 if (*elemA++ != *elemB++)
00619 return 0;
00620 }
00621 if (skip != 2 || *elemB)
00622 return 0;
00623 return 1;
00624 }
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643 int qh_setequal_skip(setT *setA, int skipA, setT *setB, int skipB) {
00644 void **elemA, **elemB, **skipAp, **skipBp;
00645
00646 elemA= SETaddr_(setA, void);
00647 elemB= SETaddr_(setB, void);
00648 skipAp= SETelemaddr_(setA, skipA, void);
00649 skipBp= SETelemaddr_(setB, skipB, void);
00650 while (1) {
00651 if (elemA == skipAp)
00652 elemA++;
00653 if (elemB == skipBp)
00654 elemB++;
00655 if (!*elemA)
00656 break;
00657 if (*elemA++ != *elemB++)
00658 return 0;
00659 }
00660 if (*elemB)
00661 return 0;
00662 return 1;
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682 void qh_setfree(setT **setp) {
00683 int size;
00684 void **freelistp;
00685
00686 if (*setp) {
00687 size= sizeof(setT) + ((*setp)->maxsize)*SETelemsize;
00688 if (size <= qhmem.LASTsize) {
00689 qh_memfree_(*setp, size, freelistp);
00690 }else
00691 qh_memfree(*setp, size);
00692 *setp= NULL;
00693 }
00694 }
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 void qh_setfree2 (setT **setp, int elemsize) {
00711 void *elem, **elemp;
00712
00713 FOREACHelem_(*setp)
00714 qh_memfree(elem, elemsize);
00715 qh_setfree(setp);
00716 }
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736 void qh_setfreelong(setT **setp) {
00737 int size;
00738
00739 if (*setp) {
00740 size= sizeof(setT) + ((*setp)->maxsize)*SETelemsize;
00741 if (size > qhmem.LASTsize) {
00742 qh_memfree(*setp, size);
00743 *setp= NULL;
00744 }
00745 }
00746 }
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761 int qh_setin(setT *set, void *setelem) {
00762 void *elem, **elemp;
00763
00764 FOREACHelem_(set) {
00765 if (elem == setelem)
00766 return 1;
00767 }
00768 return 0;
00769 }
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787 int qh_setindex(setT *set, void *atelem) {
00788 void **elem;
00789 int size, i;
00790
00791 SETreturnsize_(set, size);
00792 if (size > set->maxsize)
00793 return -1;
00794 elem= SETaddr_(set, void);
00795 for (i=0; i < size; i++) {
00796 if (*elem++ == atelem)
00797 return i;
00798 }
00799 return -1;
00800 }
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 void qh_setlarger(setT **oldsetp) {
00820 int size= 1, *sizep;
00821 setT *newset, *set, **setp, *oldset;
00822 void **oldp, **newp;
00823
00824 if (*oldsetp) {
00825 oldset= *oldsetp;
00826 SETreturnsize_(oldset, size);
00827 qhmem.cntlarger++;
00828 qhmem.totlarger += size+1;
00829 newset= qh_setnew(2 * size);
00830 oldp= SETaddr_(oldset, void);
00831 newp= SETaddr_(newset, void);
00832 memcpy((char *)newp, (char *)oldp, (size_t)(size+1) * SETelemsize);
00833 sizep= SETsizeaddr_(newset);
00834 *sizep= size+1;
00835 FOREACHset_(qhmem.tempstack) {
00836 if (set == oldset)
00837 *(setp-1)= newset;
00838 }
00839 qh_setfree(oldsetp);
00840 }else
00841 newset= qh_setnew(3);
00842 *oldsetp= newset;
00843 }
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 void *qh_setlast(setT *set) {
00859 int size;
00860
00861 if (set) {
00862 size= *SETsizeaddr_(set);
00863 if (!size)
00864 return SETelem_(set, set->maxsize - 1);
00865 else if (size > 1)
00866 return SETelem_(set, size - 2);
00867 }
00868 return NULL;
00869 }
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887 setT *qh_setnew(int setsize) {
00888 setT *set;
00889 int sizereceived;
00890 int size;
00891 void **freelistp;
00892
00893 if (!setsize)
00894 setsize++;
00895 size= sizeof(setT) + setsize * SETelemsize;
00896 if (size>0 && size <= qhmem.LASTsize) {
00897 qh_memalloc_(size, freelistp, set, setT);
00898 #ifndef qh_NOmem
00899 sizereceived= qhmem.sizetable[ qhmem.indextable[size]];
00900 if (sizereceived > size)
00901 setsize += (sizereceived - size)/SETelemsize;
00902 #endif
00903 }else
00904 set= (setT*)qh_memalloc(size);
00905 set->maxsize= setsize;
00906 set->e[setsize].i= 1;
00907 set->e[0].p= NULL;
00908 return(set);
00909 }
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930 setT *qh_setnew_delnthsorted(setT *set, int size, int nth, int prepend) {
00931 setT *newset;
00932 void **oldp, **newp;
00933 int tailsize= size - nth -1, newsize;
00934
00935 if (tailsize < 0) {
00936 qh_fprintf(qhmem.ferr, 6176, "qhull internal error (qh_setaddnth): nth %d is out-of-bounds for set:\n", nth);
00937 qh_setprint(qhmem.ferr, "", set);
00938 qh_errexit(qhmem_ERRqhull, NULL, NULL);
00939 }
00940 newsize= size-1 + prepend;
00941 newset= qh_setnew(newsize);
00942 newset->e[newset->maxsize].i= newsize+1;
00943 oldp= SETaddr_(set, void);
00944 newp= SETaddr_(newset, void) + prepend;
00945 switch (nth) {
00946 case 0:
00947 break;
00948 case 1:
00949 *(newp++)= *oldp++;
00950 break;
00951 case 2:
00952 *(newp++)= *oldp++;
00953 *(newp++)= *oldp++;
00954 break;
00955 case 3:
00956 *(newp++)= *oldp++;
00957 *(newp++)= *oldp++;
00958 *(newp++)= *oldp++;
00959 break;
00960 case 4:
00961 *(newp++)= *oldp++;
00962 *(newp++)= *oldp++;
00963 *(newp++)= *oldp++;
00964 *(newp++)= *oldp++;
00965 break;
00966 default:
00967 memcpy((char *)newp, (char *)oldp, (size_t)nth * SETelemsize);
00968 newp += nth;
00969 oldp += nth;
00970 break;
00971 }
00972 oldp++;
00973 switch (tailsize) {
00974 case 0:
00975 break;
00976 case 1:
00977 *(newp++)= *oldp++;
00978 break;
00979 case 2:
00980 *(newp++)= *oldp++;
00981 *(newp++)= *oldp++;
00982 break;
00983 case 3:
00984 *(newp++)= *oldp++;
00985 *(newp++)= *oldp++;
00986 *(newp++)= *oldp++;
00987 break;
00988 case 4:
00989 *(newp++)= *oldp++;
00990 *(newp++)= *oldp++;
00991 *(newp++)= *oldp++;
00992 *(newp++)= *oldp++;
00993 break;
00994 default:
00995 memcpy((char *)newp, (char *)oldp, (size_t)tailsize * SETelemsize);
00996 newp += tailsize;
00997 }
00998 *newp= NULL;
00999 return(newset);
01000 }
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012 void qh_setprint(FILE *fp, const char* string, setT *set) {
01013 int size, k;
01014
01015 if (!set)
01016 qh_fprintf(fp, 9346, "%s set is null\n", string);
01017 else {
01018 SETreturnsize_(set, size);
01019 qh_fprintf(fp, 9347, "%s set=%p maxsize=%d size=%d elems=",
01020 string, set, set->maxsize, size);
01021 if (size > set->maxsize)
01022 size= set->maxsize+1;
01023 for (k=0; k < size; k++)
01024 qh_fprintf(fp, 9348, " %p", set->e[k].p);
01025 qh_fprintf(fp, 9349, "\n");
01026 }
01027 }
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043 void qh_setreplace(setT *set, void *oldelem, void *newelem) {
01044 void **elemp;
01045
01046 elemp= SETaddr_(set, void);
01047 while (*elemp != oldelem && *elemp)
01048 elemp++;
01049 if (*elemp)
01050 *elemp= newelem;
01051 else {
01052 qh_fprintf(qhmem.ferr, 6177, "qhull internal error (qh_setreplace): elem %p not found in set\n",
01053 oldelem);
01054 qh_setprint(qhmem.ferr, "", set);
01055 qh_errexit(qhmem_ERRqhull, NULL, NULL);
01056 }
01057 }
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074 int qh_setsize(setT *set) {
01075 int size, *sizep;
01076
01077 if (!set)
01078 return(0);
01079 sizep= SETsizeaddr_(set);
01080 if ((size= *sizep)) {
01081 size--;
01082 if (size > set->maxsize) {
01083 qh_fprintf(qhmem.ferr, 6178, "qhull internal error (qh_setsize): current set size %d is greater than maximum size %d\n",
01084 size, set->maxsize);
01085 qh_setprint(qhmem.ferr, "set: ", set);
01086 qh_errexit(qhmem_ERRqhull, NULL, NULL);
01087 }
01088 }else
01089 size= set->maxsize;
01090 return size;
01091 }
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108 setT *qh_settemp(int setsize) {
01109 setT *newset;
01110
01111 newset= qh_setnew(setsize);
01112 qh_setappend(&qhmem.tempstack, newset);
01113 if (qhmem.IStracing >= 5)
01114 qh_fprintf(qhmem.ferr, 8123, "qh_settemp: temp set %p of %d elements, depth %d\n",
01115 newset, newset->maxsize, qh_setsize(qhmem.tempstack));
01116 return newset;
01117 }
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136 void qh_settempfree(setT **set) {
01137 setT *stackedset;
01138
01139 if (!*set)
01140 return;
01141 stackedset= qh_settemppop();
01142 if (stackedset != *set) {
01143 qh_settemppush(stackedset);
01144 qh_fprintf(qhmem.ferr, 6179, "qhull internal error (qh_settempfree): set %p(size %d) was not last temporary allocated(depth %d, set %p, size %d)\n",
01145 *set, qh_setsize(*set), qh_setsize(qhmem.tempstack)+1,
01146 stackedset, qh_setsize(stackedset));
01147 qh_errexit(qhmem_ERRqhull, NULL, NULL);
01148 }
01149 qh_setfree(set);
01150 }
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163 void qh_settempfree_all(void) {
01164 setT *set, **setp;
01165
01166 FOREACHset_(qhmem.tempstack)
01167 qh_setfree(&set);
01168 qh_setfree(&qhmem.tempstack);
01169 }
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183 setT *qh_settemppop(void) {
01184 setT *stackedset;
01185
01186 stackedset= (setT*)qh_setdellast(qhmem.tempstack);
01187 if (!stackedset) {
01188 qh_fprintf(qhmem.ferr, 6180, "qhull internal error (qh_settemppop): pop from empty temporary stack\n");
01189 qh_errexit(qhmem_ERRqhull, NULL, NULL);
01190 }
01191 if (qhmem.IStracing >= 5)
01192 qh_fprintf(qhmem.ferr, 8124, "qh_settemppop: depth %d temp set %p of %d elements\n",
01193 qh_setsize(qhmem.tempstack)+1, stackedset, qh_setsize(stackedset));
01194 return stackedset;
01195 }
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209 void qh_settemppush(setT *set) {
01210
01211 qh_setappend(&qhmem.tempstack, set);
01212 if (qhmem.IStracing >= 5)
01213 qh_fprintf(qhmem.ferr, 8125, "qh_settemppush: depth %d temp set %p of %d elements\n",
01214 qh_setsize(qhmem.tempstack), set, qh_setsize(set));
01215 }
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234 void qh_settruncate(setT *set, int size) {
01235
01236 if (size < 0 || size > set->maxsize) {
01237 qh_fprintf(qhmem.ferr, 6181, "qhull internal error (qh_settruncate): size %d out of bounds for set:\n", size);
01238 qh_setprint(qhmem.ferr, "", set);
01239 qh_errexit(qhmem_ERRqhull, NULL, NULL);
01240 }
01241 set->e[set->maxsize].i= size+1;
01242 set->e[size].p= NULL;
01243 }
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258 int qh_setunique(setT **set, void *elem) {
01259
01260 if (!qh_setin(*set, elem)) {
01261 qh_setappend(set, elem);
01262 return 1;
01263 }
01264 return 0;
01265 }
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286 void qh_setzero(setT *set, int idx, int size) {
01287 int count;
01288
01289 if (idx < 0 || idx >= size || size > set->maxsize) {
01290 qh_fprintf(qhmem.ferr, 6182, "qhull internal error (qh_setzero): index %d or size %d out of bounds for set:\n", idx, size);
01291 qh_setprint(qhmem.ferr, "", set);
01292 qh_errexit(qhmem_ERRqhull, NULL, NULL);
01293 }
01294 set->e[set->maxsize].i= size+1;
01295 count= size - idx + 1;
01296 memset((char *)SETelemaddr_(set, idx, void), 0, (size_t)count * SETelemsize);
01297 }
01298
01299