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
00034
00035
00036
00037
00038 #ifndef __SEQBITMAP_H__
00039 #define __SEQBITMAP_H__
00040
00041 #include "Bitmap4.h"
00042 #include "Bitmap8.h"
00043 #include "Bitmap16.h"
00044 #include "Bitmap32.h"
00045 #include "Bitmap64.h"
00046 #include "Tables.h"
00047 #include <fstream>
00048
00049 using namespace std;
00050
00051
00052
00053
00054
00055
00056
00057
00058 class SeqBitmap
00059 {
00060
00061
00062
00063 friend class Bitmap4;
00064 friend class Bitmap8;
00065 friend class Bitmap16;
00066 friend class Bitmap32;
00067 friend class Bitmap64;
00068
00069 public:
00070
00071 static void Init();
00072 static void MemAlloc(
00073 int size4,
00074 int size8,
00075 int size16,
00076 int size32,
00077 int size64);
00078
00079 static void MemDealloc();
00080 static void Destroy();
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 SeqBitmap(int size4, int size8, int size16, int size32, int size64)
00092 {
00093 if (size4 > 0)
00094 _bitmap4 = new Bitmap4(size4, _memory4);
00095 else
00096 _bitmap4 = 0;
00097
00098 if (size8 > 0)
00099 _bitmap8 = new Bitmap8(size8, _memory8);
00100 else
00101 _bitmap8 = 0;
00102
00103 if (size16 > 0)
00104 _bitmap16 = new Bitmap16(size16, _memory16);
00105 else
00106 _bitmap16 = 0;
00107
00108 if (size32 > 0)
00109 _bitmap32 = new Bitmap32(size32, _memory32);
00110 else
00111 _bitmap32 = 0;
00112
00113 if (size64 > 0)
00114 _bitmap64 = new Bitmap64(size64, _memory64);
00115 else
00116 _bitmap64 = 0;
00117
00118
00119
00120
00121 };
00122
00123
00124
00125
00126
00127
00128 SeqBitmap(SeqBitmap &b)
00129 {
00130
00131 if (b._bitmap4 != 0)
00132 _bitmap4 = new Bitmap4(*b._bitmap4, _memory4);
00133 else
00134 _bitmap4 = 0;
00135
00136 if (b._bitmap8 != 0)
00137 _bitmap8 = new Bitmap8(*b._bitmap8, _memory8);
00138 else
00139 _bitmap8 = 0;
00140
00141 if (b._bitmap16 != 0)
00142 _bitmap16 = new Bitmap16(*b._bitmap16, _memory16);
00143 else
00144 _bitmap16 = 0;
00145
00146 if (b._bitmap32 != 0)
00147 _bitmap32 = new Bitmap32(*b._bitmap32, _memory32);
00148 else
00149 _bitmap32 = 0;
00150
00151 if (b._bitmap64 != 0)
00152 _bitmap64 = new Bitmap64(*b._bitmap64, _memory64);
00153 else
00154 _bitmap64 = 0;
00155 };
00156
00157
00158
00159
00160 ~SeqBitmap()
00161 {
00162 if (_bitmap4 != 0)
00163 delete _bitmap4;
00164
00165 if (_bitmap8 != 0)
00166 delete _bitmap8;
00167
00168 if (_bitmap16 != 0)
00169 delete _bitmap16;
00170
00171 if (_bitmap32 != 0)
00172 delete _bitmap32;
00173
00174 if (_bitmap64 != 0)
00175 delete _bitmap64;
00176 };
00177
00178
00179
00180
00181
00182
00183 void Deallocate()
00184 {
00185 if (_bitmap4 != 0)
00186 _bitmap4->Deallocate(_memory4);
00187 if (_bitmap8 != 0)
00188 {
00189 _bitmap8->Deallocate(_memory8);
00190 }
00191 if (_bitmap16 != 0)
00192 {
00193 _bitmap16->Deallocate(_memory16);
00194 }
00195 if (_bitmap32 != 0)
00196 {
00197 _bitmap32->Deallocate(_memory32);
00198 }
00199 if (_bitmap64 != 0)
00200 {
00201 _bitmap64->Deallocate(_memory64);
00202 }
00203 }
00204
00205
00206
00207
00208
00209
00210
00211 void FillEmptyPosition(int bitmapID, int j)
00212 {
00213 switch (bitmapID)
00214 {
00215 case 0:
00216 _bitmap4->FillEmptyPosition(j);
00217 break;
00218 case 1:
00219 _bitmap8->FillEmptyPosition(j);
00220 break;
00221 case 2:
00222 _bitmap16->FillEmptyPosition(j);
00223 break;
00224 case 3:
00225 _bitmap32->FillEmptyPosition(j);
00226 break;
00227 case 4:
00228 _bitmap64->FillEmptyPosition(j);
00229 break;
00230 }
00231
00232 };
00233
00234
00235
00236
00237 int memSize()
00238 {
00239 int totalSize = 0;
00240 if (_bitmap4 != 0)
00241 totalSize += _bitmap4->_memSizeInt;
00242
00243 if (_bitmap8 != 0)
00244 totalSize += _bitmap8->_memSizeInt;
00245
00246 if (_bitmap16 != 0)
00247 totalSize += _bitmap16->_memSizeInt;
00248
00249 if (_bitmap32 != 0)
00250 totalSize += _bitmap32->_memSizeInt;
00251
00252 if (_bitmap64 != 0)
00253 totalSize += _bitmap64->_memSizeInt;
00254
00255 return totalSize * 32;
00256 };
00257
00258
00259 void Or(const SeqBitmap &b1, const SeqBitmap &b2);
00260 void And(const SeqBitmap &b1, const SeqBitmap &b2);
00261 int Count();
00262 void CreateSBitmap(const SeqBitmap &iBitmap);
00263 void CreateCBitmap(const SeqBitmap &iBitmap);
00264
00265 void PrintBitmap(ofstream& testFile);
00266
00267 void CountSmaller(
00268 int &size4,
00269 int &size8,
00270 int &size16,
00271 int &size32,
00272 int &size64,
00273 ostream& out);
00274
00275 void Compress4(
00276 SeqBitmap *refBitmap,
00277 SeqBitmap *compBitmap,
00278 int &pos4);
00279 void Compress8(
00280 SeqBitmap *refBitmap,
00281 SeqBitmap *compBitmap,
00282 int &pos4,
00283 int &pos8);
00284 void Compress16(
00285 SeqBitmap *refBitmap,
00286 SeqBitmap *compBitmap,
00287 int &pos4,
00288 int &pos8,
00289 int &pos16);
00290 void Compress32(
00291 SeqBitmap *refBitmap,
00292 SeqBitmap *compBitmap,
00293 int &pos4,
00294 int &pos8,
00295 int &pos16,
00296 int &pos32);
00297 void Compress64(
00298 SeqBitmap *refBitmap,
00299 SeqBitmap *compBitmap,
00300 int &pos4,
00301 int &pos8,
00302 int &pos16,
00303 int &pos32,
00304 int &pos64);
00305
00306 void printSizes(ostream& out);
00307
00308 static int _countOr;
00309 static int _countAnd;
00310 static int _countCount;
00311 static int _countCountZeros;
00312 static int _countCountSmaller;
00313 static int _countCreateSBitmap;
00314 static int _countCreateCBitmap;
00315
00316
00317 static unsigned int* _memory4;
00318 static unsigned int* _memory8;
00319 static unsigned short* _memory16;
00320 static unsigned int* _memory32;
00321 static unsigned int* _memory64;
00322
00323
00324 static int const _lookupTableSize;
00325 static int* _numOnesLookupTable;
00326 static int* _compress4LookupTable;
00327 static unsigned char** _compress8Table;
00328
00329
00330 static int _size4;
00331 static int _size8;
00332 static int _size16;
00333 static int _size32;
00334 static int _size64;
00335
00336 Bitmap4* _bitmap4;
00337 Bitmap8* _bitmap8;
00338 Bitmap16* _bitmap16;
00339 Bitmap32* _bitmap32;
00340 Bitmap64* _bitmap64;
00341 };
00342
00343
00344
00345 #endif