LbmSegment.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmSegment.h#16 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2006-2009 LucidEra, Inc.
00005 // Copyright (C) 2006-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_LbmSegment_Included
00023 #define Fennel_LbmSegment_Included
00024 
00025 #include "fennel/lucidera/colstore/LcsClusterNode.h"
00026 
00027 FENNEL_BEGIN_NAMESPACE
00028 
00034 class FENNEL_LBM_EXPORT LbmSegment
00035     : public boost::noncopyable
00036 {
00037 protected:
00042     LcsRid startRID;
00043 
00047     PBuffer pSegDescStart;
00048     PBuffer pSegDescEnd;
00049 
00053     PBuffer pSegStart;
00054     PBuffer pSegEnd;
00055 
00060     static const uint LbmHalfByteSize = 4;
00061 
00066     static const uint8_t LbmSegLengthMask = 0xf0;
00067 
00073     static const uint8_t LbmZeroLengthMask = 0x0f;
00074 
00081     static const uint LbmZeroLengthCompact = 12;
00082 
00088     static const uint LbmZeroLengthExtended =
00089         (uint)LbmZeroLengthMask - LbmZeroLengthCompact;
00090 
00095     static const uint LbmMaxSegSize = 16;
00096 
00107     static uint byteArray2Value(PBuffer array, uint arraySize);
00108 
00121     static uint value2ByteArray(uint value, PBuffer array, uint arraySize);
00122 
00132     uint computeSpaceForZeroBytes(uint nZeroBytes);
00133 
00147     static void readSegDescAndAdvance(
00148         PBuffer &pSegDesc, uint &bmSegLen, uint &zeroBytes);
00149 
00160     uint computeSegLength(PBuffer segDesc);
00161 
00173     uint computeSegDescLength(PBuffer segDesc);
00174 
00178     uint countSegments();
00179 
00180 public:
00188     static inline LcsRid roundToByteBoundary(LcsRid rid);
00189 
00199     static inline bool setSegLength(uint8_t &segDescByte, uint segLen);
00200 
00211     static inline bool adjustSegLength(uint8_t &segDescByte, uint segLen);
00212 
00218     static inline uint getSegLength(uint8_t segDescByte);
00219 
00225     inline uint getZeroLengthByteCount(uint8_t segDescByte);
00226 
00230     inline LcsRid getStartRID();
00231 
00235     static const uint LbmOneByteSize = 8;
00236     static const uint LbmOneByteSizeBitShift = 3;
00237     static const LcsRidPrimitive LbmOneByteSizeBitMask =
00238         0xfffffffffffffff8ULL;
00239 };
00240 
00241 inline LcsRid LbmSegment::roundToByteBoundary(LcsRid rid)
00242 {
00243     return LcsRid(opaqueToInt(rid) & LbmOneByteSizeBitMask);
00244 }
00245 
00246 inline bool LbmSegment::setSegLength(uint8_t &segDescByte, uint segLen)
00247 {
00248     if (segLen > LbmMaxSegSize) {
00249         return false;
00250     }
00251     segDescByte = (uint8_t) ((segLen - 1) << LbmHalfByteSize);
00252     return true;
00253 }
00254 
00255 inline bool LbmSegment::adjustSegLength(uint8_t &segDescByte, uint segLen)
00256 {
00257     if (segLen > LbmMaxSegSize) {
00258         return false;
00259     }
00260     segDescByte &= ~LbmSegLengthMask;
00261     segDescByte |= (uint8_t) ((segLen - 1) << LbmHalfByteSize);
00262     return true;
00263 }
00264 
00265 inline uint LbmSegment::getSegLength(uint8_t segDescByte)
00266 {
00267     return (((segDescByte & LbmSegLengthMask) >> LbmHalfByteSize) + 1);
00268 }
00269 
00270 inline uint LbmSegment::getZeroLengthByteCount(uint8_t segDescByte)
00271 {
00272     uint lengthBytes = segDescByte & LbmZeroLengthMask;
00273     if (lengthBytes > LbmZeroLengthCompact) {
00274         return (lengthBytes - LbmZeroLengthCompact);
00275     } else {
00276         return 0;
00277     }
00278 }
00279 
00280 inline LcsRid LbmSegment::getStartRID()
00281 {
00282     return startRID;
00283 }
00284 
00289 DEFINE_OPAQUE_INTEGER(LbmByteNumber, uint64_t);
00290 
00294 inline LbmByteNumber ridToByteNumber(LcsRid rid)
00295 {
00296     return LbmByteNumber(
00297         opaqueToInt(rid) >> LbmSegment::LbmOneByteSizeBitShift);
00298 }
00299 
00303 inline LcsRid byteNumberToRid(LbmByteNumber byteNum)
00304 {
00305     return LcsRid(
00306         opaqueToInt(byteNum) << LbmSegment::LbmOneByteSizeBitShift);
00307 }
00308 
00309 FENNEL_END_NAMESPACE
00310 
00311 #endif
00312 
00313 // End LbmSegment.h

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