00001
00019 #include "fxuInt.h"
00020 #include "fxu.h"
00021
00025
00026
00027 extern Fxu_Matrix * Fxu_CreateMatrix( Fxu_Data_t * pData );
00028 extern void Fxu_CreateCovers( Fxu_Matrix * p, Fxu_Data_t * pData );
00029
00030 static int s_MemoryTotal;
00031 static int s_MemoryPeak;
00032
00036
00055 int Fxu_FastExtract( Fxu_Data_t * pData )
00056 {
00057 Fxu_Matrix * p;
00058 Fxu_Single * pSingle;
00059 Fxu_Double * pDouble;
00060 int Weight1, Weight2, Weight3;
00061 int Counter = 0;
00062
00063 s_MemoryTotal = 0;
00064 s_MemoryPeak = 0;
00065
00066
00067 p = Fxu_CreateMatrix( pData );
00068 if ( p == NULL )
00069 return -1;
00070
00071
00072
00073
00074 if ( pData->fOnlyS )
00075 {
00076 pData->nNodesNew = 0;
00077 do
00078 {
00079 Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
00080 if ( pData->fVerbose )
00081 printf( "Div %5d : Best single = %5d.\r", Counter++, Weight1 );
00082 if ( Weight1 > 0 || Weight1 == 0 && pData->fUse0 )
00083 Fxu_UpdateSingle( p );
00084 else
00085 break;
00086 }
00087 while ( ++pData->nNodesNew < pData->nNodesExt );
00088 }
00089 else if ( pData->fOnlyD )
00090 {
00091 pData->nNodesNew = 0;
00092 do
00093 {
00094 Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );
00095 if ( pData->fVerbose )
00096 printf( "Div %5d : Best double = %5d.\r", Counter++, Weight2 );
00097 if ( Weight2 > 0 || Weight2 == 0 && pData->fUse0 )
00098 Fxu_UpdateDouble( p );
00099 else
00100 break;
00101 }
00102 while ( ++pData->nNodesNew < pData->nNodesExt );
00103 }
00104 else if ( !pData->fUseCompl )
00105 {
00106 pData->nNodesNew = 0;
00107 do
00108 {
00109 Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
00110 Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );
00111
00112 if ( pData->fVerbose )
00113 printf( "Div %5d : Best double = %5d. Best single = %5d.\r", Counter++, Weight2, Weight1 );
00114
00115
00116 if ( Weight1 >= Weight2 )
00117 {
00118 if ( Weight1 > 0 || Weight1 == 0 && pData->fUse0 )
00119 Fxu_UpdateSingle( p );
00120 else
00121 break;
00122 }
00123 else
00124 {
00125 if ( Weight2 > 0 || Weight2 == 0 && pData->fUse0 )
00126 Fxu_UpdateDouble( p );
00127 else
00128 break;
00129 }
00130 }
00131 while ( ++pData->nNodesNew < pData->nNodesExt );
00132 }
00133 else
00134 {
00135 pData->nNodesNew = 0;
00136 do
00137 {
00138 Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
00139 Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );
00140
00141
00142 Weight3 = Fxu_Select( p, &pSingle, &pDouble );
00143 if ( pData->fVerbose )
00144 printf( "Div %5d : Best double = %5d. Best single = %5d. Best complement = %5d.\r",
00145 Counter++, Weight2, Weight1, Weight3 );
00146
00147 if ( Weight3 > 0 || Weight3 == 0 && pData->fUse0 )
00148 Fxu_Update( p, pSingle, pDouble );
00149 else
00150 break;
00151 }
00152 while ( ++pData->nNodesNew < pData->nNodesExt );
00153 }
00154
00155 if ( pData->fVerbose )
00156 printf( "Total single = %3d. Total double = %3d. Total compl = %3d. \n",
00157 p->nDivs1, p->nDivs2, p->nDivs3 );
00158
00159
00160 if ( pData->nNodesNew )
00161 Fxu_CreateCovers( p, pData );
00162 Fxu_MatrixDelete( p );
00163
00164 if ( pData->nNodesNew == pData->nNodesExt )
00165 printf( "Warning: The limit on the number of extracted divisors has been reached.\n" );
00166 return pData->nNodesNew;
00167 }
00168
00169
00181 void Fxu_MatrixRingCubesUnmark( Fxu_Matrix * p )
00182 {
00183 Fxu_Cube * pCube, * pCube2;
00184
00185 Fxu_MatrixForEachCubeInRingSafe( p, pCube, pCube2 )
00186 pCube->pOrder = NULL;
00187 Fxu_MatrixRingCubesReset( p );
00188 }
00189
00190
00202 void Fxu_MatrixRingVarsUnmark( Fxu_Matrix * p )
00203 {
00204 Fxu_Var * pVar, * pVar2;
00205
00206 Fxu_MatrixForEachVarInRingSafe( p, pVar, pVar2 )
00207 pVar->pOrder = NULL;
00208 Fxu_MatrixRingVarsReset( p );
00209 }
00210
00211
00223 char * Fxu_MemFetch( Fxu_Matrix * p, int nBytes )
00224 {
00225 s_MemoryTotal += nBytes;
00226 if ( s_MemoryPeak < s_MemoryTotal )
00227 s_MemoryPeak = s_MemoryTotal;
00228
00229 return Extra_MmFixedEntryFetch( p->pMemMan );
00230 }
00231
00243 void Fxu_MemRecycle( Fxu_Matrix * p, char * pItem, int nBytes )
00244 {
00245 s_MemoryTotal -= nBytes;
00246
00247 Extra_MmFixedEntryRecycle( p->pMemMan, pItem );
00248 }
00249
00253
00254