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

Bitmap32.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 /// Bitmap32.h
00036 ///
00037 /////////////////////////////////////////////////////////////////////
00038 #ifndef __Bitmap32_H__
00039 #define __Bitmap32_H__
00040 
00041 #include <assert.h>
00042 #include <memory.h>
00043 #include "Tables.h"
00044 
00045 /////////////////////////////////////////////////////////////////////
00046 /// @addtogroup BitmapProcessingGroup Bitmap Processing
00047 /** @{ */
00048 
00049 /////////////////////////////////////////////////////////////////////
00050 /// A vertical representation of the data. It handles both uncompressed
00051 /// and compressed data.
00052 /// <p>
00053 /// This bitmap can represent customers with up to 32 transactions since it
00054 ///  allocates exactly 32 bits per customer
00055 /////////////////////////////////////////////////////////////////////
00056 class Bitmap32
00057 {
00058     friend class SeqBitmap;
00059 
00060 public:
00061 
00062     static void Init();
00063     static void Destroy();
00064 
00065     static int CalcSize (int numCust)
00066     {
00067         return numCust * SIZE_UINT;
00068     }
00069 
00070     /////////////////////////////////////////////////////////////////////
00071     /// Allocate the memory for Bitmap32 for this many customers
00072     ///
00073     /// @param numCustomers  # of customers
00074     /// @param memory
00075     /////////////////////////////////////////////////////////////////////
00076     Bitmap32(int numCustomers, unsigned int *&memory)
00077     {
00078         _numCust = numCustomers;
00079         ;
00080         _memSizeShort = _numCust * SHORT_PER_INT;
00081         _memSizeInt = _numCust;
00082         //_memory = new unsigned int[_memSizeInt];
00083         _memory = memory;
00084         memory += _memSizeInt * SIZE_UINT;
00085 
00086         memset(_memory, 0, _memSizeInt * SIZE_UINT);
00087     };
00088 
00089 
00090     /////////////////////////////////////////////////////////////////////
00091     /// Copy constructor
00092     ///
00093     /// @param b             Bitmap32 to copy
00094     /// @param memory
00095     /////////////////////////////////////////////////////////////////////
00096     Bitmap32(Bitmap32 &b, unsigned int *&memory)
00097     {
00098         // copy information from the source bitmap
00099         _memSizeShort = b._memSizeShort;
00100         _memSizeInt = b._memSizeInt;
00101         _numCust = b._numCust;
00102         //_memory = new unsigned int [b._memSizeInt];
00103         _memory = memory;
00104         memory += _memSizeInt * SIZE_UINT;
00105 
00106         memcpy(_memory, b._memory, _memSizeInt * SIZE_UINT);
00107     };
00108 
00109 
00110     /////////////////////////////////////////////////////////////////////
00111     /// Destructor (does nothing)
00112     /////////////////////////////////////////////////////////////////////
00113     ~Bitmap32()
00114     {
00115         //if (_memory)
00116         // delete [] _memory;
00117     };
00118 
00119     /////////////////////////////////////////////////////////////////////
00120     /// Pop this bitmap's memory from the global stack (allocation is done in
00121     /// the constructor, but deallocation is not done in the destructor
00122     /////////////////////////////////////////////////////////////////////
00123     void Deallocate(unsigned int *&memory)
00124     {
00125         memory -= (_memSizeInt * SIZE_UINT);
00126     };
00127 
00128     /////////////////////////////////////////////////////////////////////
00129     /// Fill in a 1 in a certain position
00130     ///
00131     /// @param j             bit position in Bitmap to be changed
00132     /////////////////////////////////////////////////////////////////////
00133     void FillEmptyPosition(int j)
00134     {
00135         // Locate correct int in the Bitmap
00136         int i = j / BITS_PER_INT ;
00137 
00138         // switch on correct bit
00139         _memory[i] = _memory[i] | Bit32Table[(j % BITS_PER_INT )];
00140     };
00141 
00142 
00143     // --- anding and oring two bitmap32s
00144     void Or(const Bitmap32 &b1, const Bitmap32 &b2);
00145     void And(const Bitmap32 &b1, const Bitmap32 &b2);
00146 
00147     // count the number of customers
00148     int Count();
00149     void CreateSBitmap(const Bitmap32 &iBitmap);
00150     void CreateCBitmap(const Bitmap32 &iBitmap);
00151 
00152 
00153     // ----------------------- static variables ----------------------
00154     /// counters for performance measurements
00155     static int _countOr;
00156     static int _countAnd;
00157     static int _countCount;
00158     static int _countCreateSBitmap;
00159     static int _countCreateCBitmap;
00160 
00161     /// lookup table for counting
00162     static const int _lookupTableSize;
00163 
00164     /// lookup table for creating a s-bitmap from an i-bitmap
00165     static int* _sBitmapLookupTable;
00166 
00167     /// lookup table for creating a c-bitmap for compression
00168     static int* _cBitmapLookupTable;
00169 
00170     int getIntSize() const
00171     {
00172         return _memSizeInt;
00173     }
00174 
00175 private:
00176     // --- private variables
00177     unsigned int* _memory;      ///< where data is stored
00178     int _memSizeInt;            ///< size of memory allocated in sizeof(int)
00179     int _memSizeShort;          ///< size of memory allocated in sizeof(short)
00180     int _numCust;               ///< number of customers
00181 
00182 }
00183 ; // class Bitmap32
00184 
00185 /** @} */
00186 #endif

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