Main Page | Modules | Namespace List | Data Structures | File List | Data Fields | Globals

SeqBitmap.h

Go to the documentation of this file.
00001 /*
00002  
00003 Copyright (c) 2004, Cornell University
00004 All rights reserved.
00005  
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008  
00009    - Redistributions of source code must retain the above copyright notice,
00010        this list of conditions and the following disclaimer.
00011    - Redistributions in binary form must reproduce the above copyright
00012        notice, this list of conditions and the following disclaimer in the
00013        documentation and/or other materials provided with the distribution.
00014    - Neither the name of Cornell University nor the names of its
00015        contributors may be used to endorse or promote products derived from
00016        this software without specific prior written permission.
00017  
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00028 THE POSSIBILITY OF SUCH DAMAGE.
00029  
00030 */
00031 
00032 
00033 /////////////////////////////////////////////////////////////////////
00034 ///
00035 /// SeqBitmap.h
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 /// @addtogroup BitmapProcessingGroup Bitmap Processing
00053 /** @{ */
00054 
00055 /////////////////////////////////////////////////////////////////////
00056 /// A representation of a sequence (or an item)
00057 /////////////////////////////////////////////////////////////////////
00058 class SeqBitmap
00059 {
00060 
00061     // we probably need access of Bitmap's private variables if we
00062     // put our compress code in this class
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     /// Allocate the memory for the Bitmap
00084     ///
00085     /// @param size4             size (number of 4-bits) of each bitmap
00086     /// @param size8             size (number of 4-bits) of each bitmap
00087     /// @param size16            size (number of 4-bits) of each bitmap
00088     /// @param size32            size (number of 4-bits) of each bitmap
00089     /// @param size64            size (number of 4-bits) of each bitmap
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         //debugFile.open("seqPatDebug.txt");
00121     };
00122 
00123     /////////////////////////////////////////////////////////////////////
00124     /// Copy constructor
00125     ///
00126     /// @param b                 Bitmap to copy
00127     /////////////////////////////////////////////////////////////////////
00128     SeqBitmap(SeqBitmap &b)
00129     {
00130         // Copy information from source bitmap
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     /// Deallocate memory for the Bitmap
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     /// Pop this SeqBitmap's memory from the global stack (allocation is
00180     ///     done in the constructor, but deallocation is not done in the
00181     ///     destructor
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     /// Fill in a 1 in a certain position
00207     ///
00208     /// @param j                 bit position in Bitmap to be changed
00209     /// @param bitmapID          the bitmap we want to fill data in
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     /// @return the aggregate memory size in # of ints
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     // --- other functions, refer to SeqBitmap.cpp for details
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     // Pointers to memory buffers for bitmaps
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     // lookup table for counting
00324     static int const _lookupTableSize;
00325     static int* _numOnesLookupTable;
00326     static int* _compress4LookupTable;
00327     static unsigned char** _compress8Table;
00328 
00329     // Global sizes of the bitmap stacks
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

Generated on Thu Mar 11 12:01:52 2004 for SPAM by doxygen 1.3.4