00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef XMILL
00034
00035 #include "ContMan.hpp"
00036 #include "Output.hpp"
00037 #include "Load.hpp"
00038 #include "PathDict.hpp"
00039 #include "VPathExprMan.hpp"
00040 #include "Types.hpp"
00041
00042 extern char verbose;
00043
00044 unsigned long structcontsizeorig=0;
00045 unsigned long structcontsizecompressed=0;
00046 unsigned long whitespacecontsizeorig=0;
00047 unsigned long whitespacecontsizecompressed=0;
00048 unsigned long specialcontsizeorig=0;
00049 unsigned long specialcontsizecompressed=0;
00050 unsigned long fileheadersize_orig=0;
00051 unsigned long fileheadersize_compressed=0;
00052 unsigned long compressorcontsizeorig=0;
00053 unsigned long compressorcontsizecompressed=0;
00054 unsigned long datacontsizeorig=0;
00055 unsigned long datacontsizecompressed=0;
00056
00057 void InitSpecialContainerSizeSum()
00058 {
00059 structcontsizeorig=0;
00060 structcontsizecompressed=0;
00061 whitespacecontsizeorig=0;
00062 whitespacecontsizecompressed=0;
00063 specialcontsizeorig=0;
00064 specialcontsizecompressed=0;
00065 compressorcontsizeorig=0;
00066 compressorcontsizecompressed=0;
00067 datacontsizeorig=0;
00068 datacontsizecompressed=0;
00069 }
00070
00071 void PrintSpecialContainerSizeSum()
00072 {
00073 printf("Header: Uncompressed: %8lu Compressed: %8lu (%f%%)\n",
00074 fileheadersize_orig,fileheadersize_compressed,
00075 100.0f*(float)fileheadersize_compressed/(float)fileheadersize_orig);
00076 printf("Structure: Uncompressed: %8lu Compressed: %8lu (%f%%)\n",
00077 structcontsizeorig,structcontsizecompressed,
00078 100.0f*(float)structcontsizecompressed/(float)structcontsizeorig);
00079 if(whitespacecontsizeorig!=0)
00080 printf("Whitespaces: Uncompressed: %8lu Compressed: %8lu (%f%%)\n",
00081 whitespacecontsizeorig,whitespacecontsizecompressed,
00082 100.0f*(float)whitespacecontsizecompressed/(float)whitespacecontsizeorig);
00083 if(specialcontsizeorig!=0)
00084 printf("Special: Uncompressed: %8lu Compressed: %8lu (%f%%)\n",
00085 specialcontsizeorig,specialcontsizecompressed,
00086 100.0f*(float)specialcontsizecompressed/(float)specialcontsizeorig);
00087 if(compressorcontsizeorig!=0)
00088 printf("User Compressor: Uncompressed: %8lu Compressed: %8lu (%f%%)\n",
00089 compressorcontsizeorig,compressorcontsizecompressed,
00090 100.0f*(float)compressorcontsizecompressed/(float)compressorcontsizeorig);
00091 if(datacontsizeorig!=0)
00092 printf("Data: Uncompressed: %8lu Compressed: %8lu (%f%%)\n",
00093 datacontsizeorig,datacontsizecompressed,
00094 100.0f*(float)datacontsizecompressed/(float)datacontsizeorig);
00095
00096 printf(" --------------------\n");
00097 printf("Sum: Compressed: %8lu\n",
00098 fileheadersize_compressed+structcontsizecompressed+
00099 whitespacecontsizecompressed+specialcontsizecompressed+
00100 compressorcontsizecompressed+datacontsizecompressed);
00101 }
00102
00103
00104
00105
00106 inline unsigned long CompressContainerBlock::GetDataSize()
00107
00108
00109 {
00110 unsigned long size=0;
00111
00112 for(int i=0;i<contnum;i++)
00113 size+=GetContainer(i)->GetSize();
00114
00115 return size;
00116 }
00117
00118 unsigned long CompressContainerMan::GetDataSize()
00119
00120 {
00121 CompressContainerBlock *block=blocklist;
00122 unsigned long size=0;
00123
00124
00125
00126
00127 while(block!=NULL)
00128 {
00129 size+=block->GetDataSize();
00130 block=block->nextblock;
00131 }
00132 return size;
00133 }
00134
00135 inline void CompressContainerBlock::CompressSmallContainers(Compressor *compress)
00136
00137 {
00138 for(int i=0;i<contnum;i++)
00139 {
00140 if(GetContainer(i)->GetSize()<SMALLCONT_THRESHOLD)
00141 compress->CompressMemStream(GetContainer(i));
00142 }
00143 }
00144
00145 void CompressContainerMan::CompressSmallContainers(Compressor *compress)
00146
00147 {
00148 CompressContainerBlock *block=blocklist;
00149
00150
00151
00152
00153 while(block!=NULL)
00154 {
00155 block->CompressSmallContainers(compress);
00156 block=block->nextblock;
00157 }
00158 }
00159
00160 inline void CompressContainerBlock::CompressLargeContainers(Output *output)
00161
00162 {
00163 Compressor compress(output);
00164
00165
00166
00167 if((verbose)&&(pathdictnode!=NULL))
00168 {
00169 pathdictnode->PrintInfo();
00170 printf("\n");
00171 }
00172
00173
00174
00175 unsigned long sumuncompressed=0,sumcompressed=0,
00176 uncompressedsize,compressedsize;
00177
00178
00179
00180
00181
00182
00183 if(verbose & (pathexpr!=NULL))
00184 pathexpr->GetUserCompressor()->PrintCompressInfo(
00185 GetUserDataPtr(),&sumuncompressed,&sumcompressed);
00186
00187 compressorcontsizeorig+=sumuncompressed;
00188 compressorcontsizecompressed+=sumcompressed;
00189
00190 char printsum=0;
00191
00192 if(sumuncompressed>0)
00193 printsum=1;
00194
00195 for(int i=0;i<contnum;i++)
00196 {
00197 if(verbose)
00198 {
00199 if(pathdictnode!=NULL)
00200 printf(" %4lu: ",i);
00201 else
00202 {
00203 switch(i)
00204 {
00205 case 0: printf(" Structure:");break;
00206 case 1: printf(" Whitespaces:");break;
00207 case 2: printf(" Special:");break;
00208 }
00209 }
00210 }
00211
00212 if(GetContainer(i)->GetSize()>=SMALLCONT_THRESHOLD)
00213 {
00214 sumuncompressed+=GetContainer(i)->GetSize();
00215
00216 compress.CompressMemStream(GetContainer(i));
00217 compress.FinishCompress(&uncompressedsize,&compressedsize);
00218
00219 if(verbose)
00220 printf("%8lu ==> %8lu (%f%%)\n",uncompressedsize,compressedsize,100.0f*(float)compressedsize/(float)uncompressedsize);
00221
00222 sumcompressed+=compressedsize;
00223
00224 if(pathdictnode==NULL)
00225 {
00226
00227
00228 switch(i)
00229 {
00230 case 0: structcontsizeorig+=uncompressedsize;
00231 structcontsizecompressed+=compressedsize;
00232 break;
00233 case 1: whitespacecontsizeorig+=uncompressedsize;
00234 whitespacecontsizecompressed+=compressedsize;
00235 break;
00236 case 2: specialcontsizeorig+=uncompressedsize;
00237 specialcontsizecompressed+=compressedsize;
00238 }
00239 }
00240 else
00241 {
00242 datacontsizeorig+=uncompressedsize;
00243 datacontsizecompressed+=compressedsize;
00244 }
00245 }
00246 else
00247 {
00248 if(verbose)
00249 printf("%8lu ==> Small...\n",GetContainer(i)->GetSize());
00250 }
00251 }
00252 if(verbose)
00253 {
00254 if((contnum>1)||printsum)
00255 printf(" Sum: %8lu ==> %8lu (%f%%)\n\n",sumuncompressed,sumcompressed,100.0f*(float)sumcompressed/(float)sumuncompressed);
00256 else
00257 printf("\n");
00258 }
00259 }
00260
00261 void CompressContainerMan::CompressLargeContainers(Output *output)
00262 {
00263 CompressContainerBlock *block=blocklist;
00264
00265 while(block!=NULL)
00266 {
00267 block->CompressLargeContainers(output);
00268 block=block->nextblock;
00269 }
00270 }
00271
00272
00273
00274
00275 inline void CompressContainerBlock::FinishCompress()
00276 {
00277 if(pathexpr!=NULL)
00278 pathexpr->FinishCompress(GetContainer(0),GetUserDataPtr());
00279 }
00280
00281 void CompressContainerMan::FinishCompress()
00282 {
00283 CompressContainerBlock *block=blocklist;
00284 while(block!=NULL)
00285 {
00286 block->FinishCompress();
00287 block=block->nextblock;
00288 }
00289 }
00290
00291
00292
00293
00294
00295
00296 inline void CompressContainerBlock::StoreMainInfo(MemStreamer *output)
00297 {
00298 output->StoreUInt32((pathexpr!=NULL) ? pathexpr->GetIdx() : 0);
00299 output->StoreUInt32(contnum);
00300
00301 for(int i=0;i<contnum;i++)
00302
00303 output->StoreUInt32(GetContainer(i)->GetSize());
00304 }
00305
00306 void CompressContainerMan::StoreMainInfo(MemStreamer *memstream)
00307 {
00308
00309 memstream->StoreUInt32(blocknum);
00310
00311 CompressContainerBlock *block=blocklist;
00312
00313 while(block!=NULL)
00314 {
00315 block->StoreMainInfo(memstream);
00316 block=block->nextblock;
00317 }
00318
00319
00320 }
00321
00322
00323
00324
00325 inline void CompressContainerBlock::ReleaseMemory()
00326
00327 {
00328 for(int i=0;i<contnum;i++)
00329
00330 GetContainer(i)->ReleaseMemory(0);
00331 }
00332
00333 void CompressContainerMan::ReleaseMemory()
00334 {
00335 CompressContainerBlock *block=blocklist;
00336
00337 while(block!=NULL)
00338 {
00339 block->ReleaseMemory();
00340 block=block->nextblock;
00341 }
00342
00343 containernum=0;
00344 blocknum=0;
00345 blocklist=lastblock=NULL;
00346 }
00347
00348
00349 CompressContainerBlock *CompressContainerMan::CreateNewContainerBlock(unsigned contnum,unsigned userdatasize,PathDictNode *mypathdictnode,VPathExpr *pathexpr)
00350
00351
00352
00353
00354 {
00355 CompressContainerBlock *block=new(contnum,userdatasize) CompressContainerBlock(blocknum);
00356 if(block==NULL)
00357 return NULL;
00358
00359 block->contnum=(unsigned short)contnum;
00360 block->userdatasize=(unsigned short)userdatasize;
00361
00362 block->pathdictnode=mypathdictnode;
00363 block->pathexpr=pathexpr;
00364
00365
00366 block->nextblock=NULL;
00367
00368 if(blocklist==NULL)
00369 blocklist=lastblock=block;
00370 else
00371 {
00372 lastblock->nextblock=block;
00373 lastblock=block;
00374 }
00375
00376
00377 for(unsigned i=0;i<contnum;i++)
00378 block->GetContainer(i)->Initialize();
00379
00380 blocknum++;
00381 containernum+=contnum;
00382
00383 return block;
00384 }
00385
00386 #endif