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 #ifndef CONTMAN_HPP 00034 #define CONTMAN_HPP 00035 00036 #ifdef XMILL 00037 00038 #include "MemStreamer.hpp" 00039 #include "Compress.hpp" 00040 #include "Load.hpp" 00041 00042 // Some class definitions 00043 class Output; 00044 class CompressContainerBlock; 00045 class CompressContainerMan; 00046 class PathDictNode; 00047 class SmallBlockUncompressor; 00048 class VPathExpr; 00049 00050 extern MemStreamer blockmem; 00051 00052 class CompressContainer: public MemStreamer 00053 // The main structure for representing a container 00054 // A CompressContainer is simply a MemStreamer-Object 00055 // Containers are grouped together in CompressContainerBlocks 00056 { 00057 public: 00058 void *operator new(size_t size) { return blockmem.GetByteBlock(size); } 00059 void operator delete(void *ptr) {} 00060 }; 00061 00062 class CompressContainerBlock 00063 // Used for grouping a sequence of CompressContainers together. 00064 // The sequence of CompressContainers follow *directly* the container block object 00065 // in memory. 00066 { 00067 friend CompressContainerMan; 00068 CompressContainerBlock *nextblock; // The next container block in the list 00069 unsigned short contnum; // Number of containers 00070 unsigned short userdatasize; // The compressor associated with the container 00071 // can store user data with the container block 00072 // The user data is physically stored after 00073 // the container objects. 00074 PathDictNode *pathdictnode; // The path dictionary node corresponding to the 00075 // container block 00076 VPathExpr *pathexpr; // The corresponding path expression 00077 unsigned long blockid; // The identifier of the block 00078 00079 unsigned long ComputeSmallContainerSize(); 00080 // Determines how the accumulated size of all small containers. 00081 00082 void StoreMainInfo(MemStreamer *output); 00083 // Stores the structural information about the container block 00084 // i.e. the number+size of the containers. 00085 00086 unsigned long GetDataSize(); 00087 // Computes the overall size of the container block 00088 00089 void CompressSmallContainers(Compressor *compress); 00090 // Compresses all small containers 00091 void CompressLargeContainers(Output *output); 00092 // Compresses all large containers 00093 00094 void FinishCompress(); 00095 // Is called after all small/large containers have been compressed 00096 00097 void ReleaseMemory(); 00098 // Releases all the memory after compression 00099 00100 public: 00101 void *operator new(size_t size,unsigned contnum,unsigned userdatasize) { return blockmem.GetByteBlock(size+sizeof(CompressContainer)*contnum+userdatasize); } 00102 void operator delete(void *ptr) {} 00103 #ifdef SPECIAL_DELETE 00104 void operator delete(void *ptr,unsigned contnum,unsigned userdatasize) {} 00105 #endif 00106 00107 CompressContainerBlock(unsigned long id) 00108 { 00109 blockid=id; 00110 } 00111 00112 unsigned long GetID() { return blockid; } 00113 // Returns block ID 00114 00115 CompressContainer *GetContainer(int idx) 00116 // Returns the container with index 'idx' (0<=idx<=contnum) 00117 { 00118 return (CompressContainer *)(this+1)+idx; 00119 } 00120 00121 VPathExpr *GetPathExpr() { return pathexpr; } 00122 // return the path expression of the container block 00123 00124 unsigned short GetContNum() { return contnum; } 00125 // Returns container number 00126 00127 char *GetUserDataPtr() { return (char *)(this+1)+sizeof(CompressContainer)*contnum; } 00128 // Returns a pointer to the actual user data after the container objects 00129 00130 unsigned long GetUserDataSize() { return userdatasize; } 00131 // Returns the size of the container data 00132 }; 00133 00134 //*********************************************************************************** 00135 //*********************************************************************************** 00136 //*********************************************************************************** 00137 00138 class CompressContainerMan 00139 // Manages the sequence of container blocks 00140 // (and each container block has a list of containers) 00141 { 00142 unsigned long containernum; // The number of containers 00143 unsigned long blocknum; // The number of blocks 00144 CompressContainerBlock *blocklist,*lastblock; // The list of blocks 00145 00146 public: 00147 00148 CompressContainerMan() 00149 { 00150 containernum=0; 00151 blocknum=0; 00152 blocklist=lastblock=NULL; 00153 } 00154 00155 CompressContainerBlock *CreateNewContainerBlock(unsigned contnum,unsigned userdatasize,PathDictNode *mypathdictnode,VPathExpr *pathexpr); 00156 // Creates a new container block with 'contnum' containers , with user data size 00157 // given by 'userdatasize', with the path dictionary node given by 'mypathdictnode' 00158 // and the path expression given by 'pathexpr' 00159 // If there is not enough memory, the function returns NULL. 00160 00161 void FinishCompress(); // Is called after the compression of all containers has finished 00162 00163 unsigned long GetDataSize(); // Returns the overall size of all containers 00164 00165 void StoreMainInfo(MemStreamer *memstream); 00166 // Compresses the structural information of the container blocks 00167 00168 unsigned long ComputeSmallContainerSize(); 00169 // Determines the overall size of the small containers 00170 00171 void CompressSmallContainers(Compressor *compress); 00172 // Compresses the small containers 00173 00174 void CompressLargeContainers(Output *output); 00175 // Compresses the large containers 00176 00177 void ReleaseMemory(); 00178 // Releases all the memory of the containers 00179 }; 00180 00181 //**************************************************************************** 00182 //**************************************************************************** 00183 //**************************************************************************** 00184 //**************************************************************************** 00185 00186 extern CompressContainerMan compresscontman; 00187 extern CompressContainer *globaltreecont; 00188 extern CompressContainer *globalwhitespacecont; 00189 extern CompressContainer *globalspecialcont; 00190 00191 #endif 00192 00193 #endif