DSDP
|
00001 #include "numchol.h" 00002 00003 static int ChkXlist(xlist *xt, 00004 int ind) 00005 { 00006 return (xt->port[ind]==xt->idep); 00007 } /* ChkXlist */ 00008 00009 static void XtClear(xlist *xt) 00010 { 00011 int i,sze; 00012 00013 sze =xt->last; 00014 xt->idep=xt->most+1; 00015 xt->lowp=xt->idep; 00016 xt->cure=sze; 00017 xt->ntot=0; 00018 00019 for (i=0; i<xt->idep; i++) 00020 xt->head[i]=xt->last; 00021 00022 for (i=0; i<sze; i++) { 00023 xt->port[i]=xt->idep; 00024 xt->fwrd[i]=xt->last; 00025 xt->bwrd[i]=xt->last; 00026 } 00027 } /* XtClear */ 00028 00029 int XtAlloc(int last, 00030 int most, 00031 char *info, 00032 xlist**rr) 00033 { 00034 xlist *r; 00035 int ierr=0; 00036 00037 r=(xlist*) calloc(1,sizeof(xlist)); 00038 if (!r) ExitProc(OutOfSpc,info); 00039 00040 00041 r->loca=TRUE; 00042 r->last=last; 00043 r->most=most; 00044 r->ntot=0; 00045 00046 ierr=iAlloc(most+1,info,&r->head); if(ierr) return 1; 00047 ierr=iAlloc(last,info,&r->port); if(ierr) return 1; 00048 ierr=iAlloc(last,info,&r->fwrd); if(ierr) return 1; 00049 ierr=iAlloc(last,info,&r->bwrd); if(ierr) return 1; 00050 00051 XtClear(r); 00052 00053 *rr=r; 00054 return (0); 00055 } /* XtAlloc */ 00056 00057 void XtFree(xlist **xt) 00058 { 00059 xlist *r=*xt; 00060 00061 if (r) { 00062 if (r->loca) { 00063 iFree(&r->head); 00064 iFree(&r->port); 00065 iFree(&r->fwrd); 00066 iFree(&r->bwrd); 00067 } 00068 free(r); 00069 *xt=NULL; 00070 } 00071 } /* XtFree */ 00072 00073 int XtSucc(xlist *xt) 00074 { 00075 int t,last=xt->last,most=xt->most, 00076 *head; 00077 00078 if (xt->cure==last) 00079 return (FALSE); 00080 00081 if (xt->fwrd[xt->cure]!=last) 00082 xt->cure=xt->fwrd[xt->cure]; 00083 00084 else { 00085 head=xt->head; 00086 00087 for(t=xt->port[xt->cure]+1; t<=most && head[t]==last; ++t); 00088 00089 if (t>most) 00090 xt->cure=last; 00091 else 00092 xt->cure=xt->head[t]; 00093 } 00094 00095 return (TRUE); 00096 } /* XtSucc */ 00097 00098 void XtDel(xlist *xt, 00099 int e) 00100 { 00101 int p; 00102 00103 if (!ChkXlist(xt,e)) { 00104 00105 if (xt->ntot<=0) 00106 ExitProc(SysError,NULL); 00107 00108 xt->ntot--; 00109 00110 if (xt->cure==e) { 00111 if (xt->ntot) 00112 XtSucc(xt); 00113 else 00114 xt->cure=xt->last; 00115 } 00116 00117 p =xt->port[e]; 00118 xt->port[e]=xt->idep; 00119 00120 if (xt->bwrd[e]!=xt->last) 00121 xt->fwrd[xt->bwrd[e]]=xt->fwrd[e]; 00122 else 00123 xt->head[p]=xt->fwrd[e]; 00124 00125 if (xt->fwrd[e]!=xt->last) 00126 xt->bwrd[xt->fwrd[e]]=xt->bwrd[e]; 00127 00128 if (xt->head[p]==xt->last && 00129 xt->lowp==p) { 00130 xt->lowp=xt->idep; 00131 if (xt->ntot) { 00132 for(++p; p<=xt->most; ++p){ 00133 if (xt->head[p]!=xt->last){ 00134 xt->lowp=p; 00135 break; 00136 } 00137 } 00138 } 00139 } 00140 } 00141 } /* XtDel */ 00142 00143 void XtPut(xlist *xt, 00144 int e, 00145 int p) 00146 { 00147 if (0<=e && e<xt->last && 0<=p && p<=xt->most) { 00148 XtDel(xt,e); 00149 xt->ntot++; 00150 xt->port[e] =p; 00151 xt->fwrd[e] =xt->head[p]; 00152 xt->bwrd[e]=xt->last; 00153 00154 if (xt->head[p]!=xt->last) 00155 xt->bwrd[xt->head[p]]=e; 00156 00157 xt->head[p]=e; 00158 xt->lowp =min(p,xt->lowp); 00159 } 00160 00161 else 00162 ExitProc(SysError,NULL); 00163 } /* XtPut */ 00164 00165 int XtLeast(xlist *xt) 00166 { 00167 if (xt->lowp==xt->idep) { 00168 if (xt->ntot!=0) 00169 ExitProc(SysError,NULL); 00170 00171 xt->cure=xt->last; 00172 return FALSE; 00173 } 00174 00175 else { 00176 if (xt->ntot<=0) 00177 ExitProc(SysError,NULL); 00178 00179 xt->cure=xt->head[xt->lowp]; 00180 return TRUE; 00181 } 00182 } /* XtLeast */ 00183 00184 int XtGet(xlist *xt, 00185 int *e, 00186 int *p) 00187 { 00188 if (xt->cure>xt->last) 00189 ExitProc(SysError,NULL); 00190 00191 if (xt->cure==xt->last) 00192 return FALSE; 00193 00194 *e=xt->cure; 00195 *p=xt->port[*e]; 00196 00197 return TRUE; 00198 } /* XtGet */