Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ContMan.cpp

Go to the documentation of this file.
00001 /*
00002 This product contains certain software code or other information
00003 ("AT&T Software") proprietary to AT&T Corp. ("AT&T").  The AT&T
00004 Software is provided to you "AS IS".  YOU ASSUME TOTAL RESPONSIBILITY
00005 AND RISK FOR USE OF THE AT&T SOFTWARE.  AT&T DOES NOT MAKE, AND
00006 EXPRESSLY DISCLAIMS, ANY EXPRESS OR IMPLIED WARRANTIES OF ANY KIND
00007 WHATSOEVER, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00008 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WARRANTIES OF
00009 TITLE OR NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS, ANY
00010 WARRANTIES ARISING BY USAGE OF TRADE, COURSE OF DEALING OR COURSE OF
00011 PERFORMANCE, OR ANY WARRANTY THAT THE AT&T SOFTWARE IS "ERROR FREE" OR
00012 WILL MEET YOUR REQUIREMENTS.
00013 
00014 Unless you accept a license to use the AT&T Software, you shall not
00015 reverse compile, disassemble or otherwise reverse engineer this
00016 product to ascertain the source code for any AT&T Software.
00017 
00018 (c) AT&T Corp. All rights reserved.  AT&T is a registered trademark of AT&T Corp.
00019 
00020 ***********************************************************************
00021 
00022 History:
00023 
00024       24/11/99  - initial release by Hartmut Liefke, liefke@seas.upenn.edu
00025                                      Dan Suciu,      suciu@research.att.com
00026 */
00027 
00028 //*************************************************************************************
00029 //*************************************************************************************
00030 
00031 // This module contains the container manager for the compressor XMill
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; // We need to reference the 'verbose' flag
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    // Computes the overall size of the container block
00108    // by size of the containers
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    // Computes the overall size of all containers
00120 {
00121    CompressContainerBlock  *block=blocklist;
00122    unsigned long           size=0;
00123 
00124    // First, we compress all small containers using the
00125    // same compressor
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    // Compresses the small containers in the container block
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    // Compresses the small containers of all container blocks
00147 {
00148    CompressContainerBlock *block=blocklist;
00149 
00150    // First, we compress all small containers using the
00151    // same compressor
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    // Compresses the large containers of the block
00162 {
00163    Compressor        compress(output);
00164 
00165    // In 'verbose' mode, we output information about the
00166    // path dictionary
00167    if((verbose)&&(pathdictnode!=NULL))
00168    {
00169       pathdictnode->PrintInfo();
00170       printf("\n");
00171    }
00172 
00173    // Each (large) container is compressed separately
00174    
00175    unsigned long  sumuncompressed=0,sumcompressed=0,
00176                   uncompressedsize,compressedsize;
00177 
00178    // First, we print the status information of the user compressors.
00179    // For example, for dictionary compressors, the dictonary
00180    // must be compressed - hence, we output the size of the
00181    // dictionary before and after compression
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)  // Do we have a normal block?
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)  // The first block?
00225          {
00226             // For the three special container, we keep track of the sum
00227             // of the (un)compressed data size
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       // First, we store the number of data containers
00303       output->StoreUInt32(GetContainer(i)->GetSize());
00304 }
00305 
00306 void CompressContainerMan::StoreMainInfo(MemStreamer *memstream)
00307 {
00308    // First, we store the number of container block
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 //   compressor->CompressMemStream(memstream);
00320 }
00321 
00322 //*************************************************************************
00323 //*************************************************************************
00324 
00325 inline void CompressContainerBlock::ReleaseMemory()
00326    // Releases the memory of the containers
00327 {
00328    for(int i=0;i<contnum;i++)
00329       // Let's release the memory of all containers
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    // Creates a new container block with 'contnum' containers , with user data size
00351    // given by 'userdatasize', with the path dictionary node given by 'mypathdictnode'
00352    // and the path expression given by 'pathexpr'
00353    // If there is not enough memory, the function returns NULL.
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    // Let's add the container block at the end of the list
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    // We initialize the memory for all the containers
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

Generated on Sat Oct 13 16:08:34 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001