00001 00021 #ifndef __CUT_LIST_H__ 00022 #define __CUT_LIST_H__ 00023 00027 00031 00035 00036 typedef struct Cut_ListStruct_t_ Cut_List_t; 00037 struct Cut_ListStruct_t_ 00038 { 00039 Cut_Cut_t * pHead[CUT_SIZE_MAX+1]; 00040 Cut_Cut_t ** ppTail[CUT_SIZE_MAX+1]; 00041 }; 00042 00046 00050 00062 static inline void Cut_ListStart( Cut_List_t * p ) 00063 { 00064 int i; 00065 for ( i = 1; i <= CUT_SIZE_MAX; i++ ) 00066 { 00067 p->pHead[i] = 0; 00068 p->ppTail[i] = &p->pHead[i]; 00069 } 00070 } 00071 00083 static inline void Cut_ListAdd( Cut_List_t * p, Cut_Cut_t * pCut ) 00084 { 00085 assert( pCut->nLeaves > 0 && pCut->nLeaves <= CUT_SIZE_MAX ); 00086 *p->ppTail[pCut->nLeaves] = pCut; 00087 p->ppTail[pCut->nLeaves] = &pCut->pNext; 00088 } 00089 00101 static inline void Cut_ListAdd2( Cut_List_t * p, Cut_Cut_t * pCut ) 00102 { 00103 extern int Cut_CutCompare( Cut_Cut_t * pCut1, Cut_Cut_t * pCut2 ); 00104 Cut_Cut_t * pTemp, ** ppSpot; 00105 assert( pCut->nLeaves > 0 && pCut->nLeaves <= CUT_SIZE_MAX ); 00106 if ( p->pHead[pCut->nLeaves] != NULL ) 00107 { 00108 ppSpot = &p->pHead[pCut->nLeaves]; 00109 for ( pTemp = p->pHead[pCut->nLeaves]; pTemp; pTemp = pTemp->pNext ) 00110 { 00111 if ( Cut_CutCompare(pCut, pTemp) < 0 ) 00112 { 00113 *ppSpot = pCut; 00114 pCut->pNext = pTemp; 00115 return; 00116 } 00117 else 00118 ppSpot = &pTemp->pNext; 00119 } 00120 } 00121 *p->ppTail[pCut->nLeaves] = pCut; 00122 p->ppTail[pCut->nLeaves] = &pCut->pNext; 00123 } 00124 00136 static inline void Cut_ListDerive( Cut_List_t * p, Cut_Cut_t * pList ) 00137 { 00138 Cut_Cut_t * pPrev; 00139 int nLeaves; 00140 Cut_ListStart( p ); 00141 while ( pList != NULL ) 00142 { 00143 nLeaves = pList->nLeaves; 00144 p->pHead[nLeaves] = pList; 00145 for ( pPrev = pList, pList = pList->pNext; pList; pPrev = pList, pList = pList->pNext ) 00146 if ( nLeaves < (int)pList->nLeaves ) 00147 break; 00148 p->ppTail[nLeaves] = &pPrev->pNext; 00149 pPrev->pNext = NULL; 00150 } 00151 } 00152 00164 static inline void Cut_ListAddList( Cut_List_t * pOld, Cut_List_t * pNew ) 00165 { 00166 int i; 00167 for ( i = 1; i <= CUT_SIZE_MAX; i++ ) 00168 { 00169 if ( pNew->pHead[i] == NULL ) 00170 continue; 00171 *pOld->ppTail[i] = pNew->pHead[i]; 00172 pOld->ppTail[i] = pNew->ppTail[i]; 00173 } 00174 } 00175 00187 static inline Cut_Cut_t * Cut_ListFinish( Cut_List_t * p ) 00188 { 00189 Cut_Cut_t * pHead = NULL, ** ppTail = &pHead; 00190 int i; 00191 for ( i = 1; i <= CUT_SIZE_MAX; i++ ) 00192 { 00193 if ( p->pHead[i] == NULL ) 00194 continue; 00195 *ppTail = p->pHead[i]; 00196 ppTail = p->ppTail[i]; 00197 } 00198 *ppTail = NULL; 00199 return pHead; 00200 } 00201 00202 #endif 00203 00207