LbmByteSegment.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmByteSegment.h#11 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 LucidEra, Inc.
00005 // Copyright (C) 2005-2009 The Eigenbase Project
00006 //
00007 // This program is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU General Public License as published by the Free
00009 // Software Foundation; either version 2 of the License, or (at your option)
00010 // any later version approved by The Eigenbase Project.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 #ifndef Fennel_LbmByteSegment_Included
00023 #define Fennel_LbmByteSegment_Included
00024 
00025 #include "fennel/common/ByteBuffer.h"
00026 #include "fennel/lucidera/bitmap/LbmSegment.h"
00027 #include "fennel/tuple/TupleData.h"
00028 
00029 FENNEL_BEGIN_NAMESPACE
00030 
00035 class FENNEL_LBM_EXPORT LbmByteSegment
00036 {
00037 public:
00038     static const uint bitsInByte[];
00039 
00040     LbmByteNumber byteNum;
00041     PBuffer byteSeg;
00042     uint len;
00043 
00044     inline void reset()
00045     {
00046         byteNum = (LbmByteNumber) 0;
00047         byteSeg = NULL;
00048         len = 0;
00049     }
00050 
00054     inline LcsRid getSrid() const
00055     {
00056         return byteNumberToRid(byteNum);
00057     }
00058 
00062     inline bool isNull() const
00063     {
00064         return byteSeg == NULL;
00065     }
00066 
00070     inline LbmByteNumber getEnd() const
00071     {
00072         return byteNum + len;
00073     }
00074 
00078     inline LcsRid getEndRid() const
00079     {
00080         return byteNumberToRid(getEnd());
00081     }
00082 
00090     void advanceToByteNum(LbmByteNumber newStartByteNum)
00091     {
00092         // ignore null values
00093         if (isNull()) {
00094             return;
00095         }
00096 
00097         // check if the segment will have valid data after truncation
00098         if (getEnd() <= newStartByteNum) {
00099             reset();
00100             return;
00101         }
00102 
00103         // advance the segment in place if required
00104         if (byteNum < newStartByteNum) {
00105             uint diff = opaqueToInt(newStartByteNum - byteNum);
00106             byteNum += diff;
00107             byteSeg -= diff;
00108             len -= diff;
00109         }
00110     }
00111 
00115     uint countBits()
00116     {
00117         return countBits(byteSeg - len + 1, len);
00118     }
00119 
00124     static uint countBits(TupleDatum const &datum)
00125     {
00126         if (datum.pData == NULL || datum.cbData == 0) {
00127             return 1;
00128         }
00129         return countBits(datum.pData, datum.cbData);
00130     }
00131 
00135     static uint countBits(PConstBuffer pBuf, uint len)
00136     {
00137         uint total = 0;
00138         for (uint i = 0; i < len; i++) {
00139             total += bitsInByte[pBuf[i]];
00140         }
00141         return total;
00142     }
00143 
00144     static void verifyBitsInByte()
00145     {
00146         for (uint i = 0; i < 256; i++) {
00147             uint slowBits = 0;
00148             for (uint j = 0; j < 8; j++) {
00149                 if (i & (1 << j)) {
00150                     slowBits++;
00151                 }
00152             }
00153             assert (slowBits == bitsInByte[i]);
00154         }
00155     }
00156 
00162     void print(std::ostream &output)
00163     {
00164         output << std::dec << opaqueToInt(byteNum) << ".";
00165         output << std::dec << len << " (";
00166         for (uint i = 0; i < len; i++) {
00167             uint val = byteSeg[i];
00168             if (i > 0) {
00169                 output << ",";
00170             }
00171             output << std::hex << val;
00172         }
00173         output << ")" << std::endl;
00174     }
00175 };
00176 
00177 FENNEL_END_NAMESPACE
00178 
00179 #endif
00180 
00181 // End LbmByteSegment.h

Generated on Mon Jun 22 04:00:19 2009 for Fennel by  doxygen 1.5.1