#include #define tofiles 1 /* 1=write to files, 0=write info to screen (max k=9) */ #define infinity (1<<30) /* 2^30 is close enough */ #define int32 int /* program uses 32 bit integers (not 64) to save memory */ #define masktype int32 /* used to declare bit masks */ //ones(x) returns the number of ones in bit mask x [up to 24] #define ones(x) ((x&1)+((x>>1)&1)+((x>>2)&1)+((x>>3)&1)+((x>>4)&1)+((x>>5)&1)+((x>>6)&1)+((x>>7)&1)+((x>>8)&1)+((x>>9)&1)+((x>>10)&1)+((x>>11)&1)+((x>>12)&1)+((x>>13)&1)+((x>>14)&1)+((x>>15)&1)+((x>>16)&1)+((x>>17)&1)+((x>>18)&1)+((x>>19)&1)+((x>>20)&1)+((x>>21)&1)+((x>>22)&1)+((x>>23)&1)+((x>>24)&1)) //highbit(x) returns location of the highest one in bit mask x [up to 24] #define highbit(x) ((x>>15)?(x>>23)?(x>>24)?24:23:(x>>19)?(x>>21)?(x>>22)?22:21:(x>>20)?20:19:(x>>17)?(x>>18)?18:17:(x>>16)?16:15:(x>>7)?(x>>11)?(x>>13)?(x>>14)?14:13:(x>>12)?12:11:(x>>9)?(x>>10)?10:9:(x>>8)?8:7:(x>>3)?(x>>5)?(x>>6)?6:5:(x>>4)?4:3:(x>>1)?(x>>2)?2:1:(x)?0:(-1)) #define max1(a,b) (((a)>b)?((a)>1)?(a):1:((b)>1)?(b):1) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)>(b)?(b):(a)) #define numClasses (1<<(k-1)) /* 2^(k-1) */ #define makesure(op,msg) {if((op)==0){fprintf(stderr,msg);exit(17);}} #define allocErr "Allocation Error" //printset is used to print bitmask info to the screen #define printset(x,f) for(c1=0;c1<16;c1++){if(x&(1<1)\n"); exit(1); } sscanf (argv[1],"%d",&ktemp); k = ktemp; b = bA[k]; if (k<2) { fprintf(stderr,"command needs one integer argument (>1)\n"); exit(1);} if (k>23) { fprintf(stderr,"Surely, you jest\n"); exit(1);} maskmaxminus = 1<<(k)-1; maskmaxplus = maskmaxminus*2; makesure(Sminus = (masktype *)calloc(b,sizeof(masktype)),allocErr); makesure(Splus = (masktype *)calloc(b,sizeof(masktype)),allocErr); makesure(j = (signed char *)calloc(b,sizeof(char)),allocErr); makesure(minK = (signed char *)calloc(b,sizeof(char)),allocErr); makesure(SclassMap = (unsigned int32 *)calloc(numClasses,sizeof(int32)),allocErr); makesure(succs = (unsigned int32 *)calloc(numClasses*k,sizeof(int32)),allocErr); makesure(succInx=(unsigned int32 *)calloc(b,sizeof(int32)),allocErr); makesure(preds = (unsigned int32 *)calloc(numClasses*(k+1),sizeof(int32)),allocErr); makesure(predInx=(unsigned int32 *)calloc(b,sizeof(int32)),allocErr); makesure(predLoc=(signed char *)calloc(b,sizeof(char)),allocErr); makesure(predCount = (unsigned int32 *)calloc(numClasses,sizeof(int32)),allocErr); for (c=0;c>10)+1); SclassCount=succCount=0; for (candSplus=0; candSplus<=maskmaxplus; candSplus+=2) { maskmaxtemp = min(maskmaxminus,(1<<(k-(highPlus=highbit(candSplus))))-1); for (candSminus=0; candSminus<=maskmaxtemp; candSminus++) { if (ones(candSplus) == ones(candSminus)) // S-plus & S-minus equal size { highMinus=highbit(candSminus); SclassMap[SclassCount]=succCount; for (candj=1; candj>10)+1); } for (candSclass=0;candSclass>1) ==(Splus[candSrce]-(1<<(-j[candSrce]))))); } else /* situation (b) */ { adj=(((Sminus[candDest]<<1)==Sminus[candSrce]) && ((Splus[candDest]>>1)==(Splus[candSrce]+1-(1<<(-j[candSrce]))))); } } else if (j[candSrce]>0) { if (Sminus[candSrce]&1) /* situation (d) */ { adj=(((Splus[candDest]>>1)==Splus[candSrce]) && ((Sminus[candDest]<<1)==(Sminus[candSrce]-1+(1<<(j[candSrce]))))); } else /* situation (e) */ { adj=(((Splus[candDest]>>1)==(Splus[candSrce]+1)) && ((Sminus[candDest]<<1) ==(Sminus[candSrce]+(1<<(j[candSrce]))))); } } else /* situation (c) */ { if (((Splus[candDest]>>1)==Splus[candSrce]) && ((Sminus[candDest]<<1)==Sminus[candSrce])) {adj=1;} } } if (adj) /* there is an arc from candSrce to candDest */ { succInx[candSrce]=candSclass; preds[candSclass*(k+1)+predCount[candSclass]]=candSrce; predLoc[candSrce]=predCount[candSclass]; predCount[candSclass]++; candSclass=numClasses; } } } for (predsCount=predsPoint=c=0;c