00001
00019 #include "mvc.h"
00020
00024
00025 static void Mvc_CoverRemoveDuplicates( Mvc_Cover_t * pCover );
00026 static void Mvc_CoverRemoveContained( Mvc_Cover_t * pCover );
00027
00031
00032
00044 int Mvc_CoverContain( Mvc_Cover_t * pCover )
00045 {
00046 int nCubes;
00047 nCubes = Mvc_CoverReadCubeNum( pCover );
00048 if ( nCubes < 2 )
00049 return 0;
00050 Mvc_CoverSetCubeSizes(pCover);
00051 Mvc_CoverSort( pCover, NULL, Mvc_CubeCompareSizeAndInt );
00052 Mvc_CoverRemoveDuplicates( pCover );
00053 if ( nCubes > 1 )
00054 Mvc_CoverRemoveContained( pCover );
00055 return (nCubes != Mvc_CoverReadCubeNum(pCover));
00056 }
00057
00069 void Mvc_CoverRemoveDuplicates( Mvc_Cover_t * pCover )
00070 {
00071 Mvc_Cube_t * pPrev, * pCube, * pCube2;
00072 int fEqual;
00073
00074
00075 pPrev = Mvc_CoverReadCubeHead(pCover);
00076
00077 Mvc_CoverForEachCubeStartSafe( Mvc_CubeReadNext(pPrev), pCube, pCube2 )
00078 {
00079
00080 Mvc_CubeBitEqual( fEqual, pPrev, pCube );
00081 if ( fEqual )
00082 {
00083 Mvc_CoverDeleteCube( pCover, pPrev, pCube );
00084 Mvc_CubeFree( pCover, pCube );
00085
00086 }
00087 else
00088 {
00089 pPrev = pCube;
00090 }
00091 }
00092 }
00093
00105 void Mvc_CoverRemoveContained( Mvc_Cover_t * pCover )
00106 {
00107 Mvc_Cube_t * pCubeBeg, * pCubeEnd, * pCubeLarge;
00108 Mvc_Cube_t * pCube, * pCube2, * pPrev;
00109 unsigned sizeCur;
00110 int Result;
00111
00112
00113
00114
00115 pCubeBeg = Mvc_CoverReadCubeHead(pCover);
00116 do
00117 {
00118
00119 sizeCur = Mvc_CubeReadSize(pCubeBeg);
00120
00121
00122 pCubeEnd = pCubeBeg;
00123
00124 Mvc_CoverForEachCubeStart( Mvc_CubeReadNext(pCubeBeg), pCube )
00125 {
00126 if ( sizeCur == Mvc_CubeReadSize(pCube) )
00127 pCubeEnd = pCube;
00128 else
00129 break;
00130 }
00131
00132
00133 if ( pCube == NULL )
00134 break;
00135
00136
00137
00138
00139 Mvc_CoverForEachCubeStart( pCubeBeg, pCubeLarge )
00140 {
00141 pPrev = pCubeEnd;
00142 Mvc_CoverForEachCubeStartSafe( Mvc_CubeReadNext(pCubeEnd), pCube, pCube2 )
00143 {
00144
00145 Mvc_CubeBitNotImpl( Result, pCube, pCubeLarge );
00146 if ( !Result )
00147 {
00148 Mvc_CoverDeleteCube( pCover, pPrev, pCube );
00149 Mvc_CubeFree( pCover, pCube );
00150
00151 }
00152 else
00153 {
00154 pPrev = pCube;
00155 }
00156 }
00157
00158 if ( pCubeLarge == pCubeEnd )
00159 break;
00160 }
00161
00162
00163 pCubeBeg = Mvc_CubeReadNext(pCubeEnd);
00164 }
00165 while ( pCubeBeg );
00166 }
00167
00168
00172
00173