LbmSegmentReader.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmSegmentReader.cpp#11 $
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 #include "fennel/common/CommonPreamble.h"
00023 #include "fennel/exec/ExecStreamBufAccessor.h"
00024 #include "fennel/lucidera/bitmap/LbmSegmentReader.h"
00025 
00026 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSegmentReader.cpp#11 $");
00027 
00028 void LbmSegmentReader::init(
00029     SharedExecStreamBufAccessor &pInAccessorInit,
00030     TupleData &bitmapSegTuple)
00031 {
00032     init(pInAccessorInit, bitmapSegTuple, false, NULL);
00033 }
00034 
00035 void LbmSegmentReader::init(
00036     SharedExecStreamBufAccessor &pInAccessorInit,
00037     TupleData &bitmapSegTuple,
00038     bool setBitmapInit,
00039     boost::dynamic_bitset<> *pBitmapInit)
00040 {
00041     LbmSegmentReaderBase::init(
00042         pInAccessorInit,
00043         bitmapSegTuple,
00044         setBitmapInit,
00045         pBitmapInit);
00046     initCommon();
00047 }
00048 
00049 void LbmSegmentReader::init(
00050     SharedLbmTupleReader &pTupleReaderInit,
00051     TupleData &bitmapSegTuple)
00052 {
00053     init(pTupleReaderInit, bitmapSegTuple, false, NULL);
00054 }
00055 
00056 void LbmSegmentReader::init(
00057     SharedLbmTupleReader &pTupleReaderInit,
00058     TupleData &bitmapSegTuple,
00059     bool setBitmapInit,
00060     boost::dynamic_bitset<> *pBitmapInit)
00061 {
00062     LbmSegmentReaderBase::init(
00063         pTupleReaderInit,
00064         bitmapSegTuple,
00065         setBitmapInit,
00066         pBitmapInit);
00067     initCommon();
00068 }
00069 
00070 void LbmSegmentReader::initCommon()
00071 {
00072     firstReadDone = false;
00073 }
00074 
00075 ExecStreamResult LbmSegmentReader::readSegment()
00076 {
00077     ExecStreamResult rc = readBitmapSegTuple();
00078     if (rc != EXECRC_YIELD) {
00079         return rc;
00080     }
00081 
00082     if (pSegDescStart) {
00083         // in the case where the segment contains a descriptor,
00084         // set some initial values to make the first call to advanceToByte()
00085         // read the descriptor and point to the first bitmap in the segment
00086         byteSegLen = 0;
00087         return advanceToByte(byteSegOffset);
00088     }
00089 
00090     return EXECRC_YIELD;
00091 }
00092 
00093 ExecStreamResult LbmSegmentReader::advanceToByte(LbmByteNumber byteNum)
00094 {
00095     // read byte segments until find a suitable one
00096     while (byteSegOffset + byteSegLen <= byteNum) {
00097         // if current segment is exhausted, read another
00098         if (pSegDescStart >= pSegDescEnd) {
00099             ExecStreamResult rc = readSegment();
00100             if (rc != EXECRC_YIELD) {
00101                 return rc;
00102             }
00103             firstReadDone = true;
00104             continue;
00105         }
00106 
00107         // advance to the next segment
00108         advanceSegment();
00109     }
00110 
00111     // Found a suitable segment, or were on a suitable one to begin
00112     // with.  Move to correct position within segment.
00113     if (byteNum > byteSegOffset) {
00114         uint delta = opaqueToInt(byteNum - byteSegOffset);
00115         byteSegLen -= delta;
00116         pSegStart -= delta;
00117         byteSegOffset += delta;
00118     }
00119 
00120     return EXECRC_YIELD;
00121 }
00122 
00123 ExecStreamResult LbmSegmentReader::advanceToRid(LcsRid rid)
00124 {
00125     return advanceToByte(ridToByteNumber(rid));
00126 }
00127 
00128 void LbmSegmentReader::readCurrentByteSegment(
00129     LcsRid &startRid, PBuffer &byteSeg, uint &len)
00130 {
00131     assert(firstReadDone);
00132     startRid = byteNumberToRid(byteSegOffset);
00133     byteSeg = pSegStart;
00134     len = byteSegLen;
00135     // assumes advanceToByte() has been called to move to a segment
00136     // that has actual bits set, and intermediate zeros have been removed
00137     assert(*byteSeg != 0);
00138     assert(len > 0);
00139 }
00140 
00141 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSegmentReader.cpp#11 $");
00142 
00143 // End LbmSegmentReader.cpp

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