LbmRidReader.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmRidReader.h#10 $
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_LbmRidReader_Included
00023 #define Fennel_LbmRidReader_Included
00024 
00025 #include "fennel/btree/BTreeReader.h"
00026 #include "fennel/exec/ExecStreamDefs.h"
00027 #include "fennel/lucidera/bitmap/LbmEntry.h"
00028 #include "fennel/lucidera/bitmap/LbmSegmentReader.h"
00029 #include "fennel/lucidera/bitmap/LbmTupleReader.h"
00030 
00031 FENNEL_BEGIN_NAMESPACE
00032 
00033 class LbmSingleTupleReader;
00034 
00043 class LbmRidReaderBase : public LbmSegment
00044 {
00045 protected:
00049     LbmSegmentReader segmentReader;
00050 
00054     bool firstReadDone;
00055 
00059     uint curByte;
00060 
00064     LcsRid curRid;
00065 
00069     bool moveNext;
00070 
00074     LcsRid nextRid;
00075 
00080     void resetState();
00081 
00088     ExecStreamResult searchForNextRid();
00089 
00093     void initCommon();
00094 
00095 public:
00104     ExecStreamResult advanceToRid(LcsRid rid);
00105 
00114     ExecStreamResult readRidAndAdvance(LcsRid &rid);
00115 };
00116 
00120 class LbmRidReader : public LbmRidReaderBase
00121 {
00122 public:
00131     void init(
00132         SharedExecStreamBufAccessor &pInAccessorInit,
00133         TupleData &bitmapSegTuple);
00134 };
00135 
00143 class FENNEL_LBM_EXPORT LbmIterableRidReader
00144     : protected LbmRidReaderBase
00145 {
00146 protected:
00150     bool buffered;
00151 
00155     LcsRid bufferedRid;
00156 
00160     void initCommon();
00161 
00167     inline bool searchForNextRid();
00168 
00169 public:
00175     inline bool hasNext();
00176 
00183     inline LcsRid peek();
00184 
00189     inline void advance();
00190 
00197     inline LcsRid getNext();
00198 };
00199 
00203 class FENNEL_LBM_EXPORT LbmTupleRidReader
00204     : public LbmIterableRidReader
00205 {
00209     LbmSingleTupleReader *pReader;
00210 
00214     SharedLbmTupleReader pSharedReader;
00215 
00216 public:
00223     void init(TupleData &bitmapSegTuple);
00224 };
00225 
00229 class FENNEL_LBM_EXPORT LbmDeletionIndexReader
00230 {
00234     SharedBTreeReader btreeReader;
00235 
00239     TupleData *pBitmapSegTuple;
00240 
00244     TupleData searchEntry;
00245 
00249     bool currTuple;
00250 
00254     LbmTupleRidReader ridReader;
00255 
00259     LcsRid btreeRid;
00260 
00264     bool emptyIndex;
00265 
00269     bool emptyIndexUnknown;
00270 
00275     void initRidReader();
00276 
00277 public:
00278     ~LbmDeletionIndexReader();
00279 
00288     void init(
00289         SharedBTreeReader &btreeReader,
00290         TupleData &bitmapSegTuple);
00291 
00295     void endSearch();
00296 
00300     bool isEmpty();
00301 
00309     bool searchForRid(LcsRid rid);
00310 };
00311 
00312 /**************************************************************
00313   Definitions of inline methods for class LbmIterableRidReader
00314 ***************************************************************/
00315 
00316 inline bool LbmIterableRidReader::searchForNextRid()
00317 {
00318     ExecStreamResult rc = readRidAndAdvance(bufferedRid);
00319     switch (rc) {
00320     case EXECRC_YIELD:
00321         buffered = true;
00322         break;
00323     case EXECRC_EOS:
00324         buffered = false;
00325         break;
00326     default:
00327         permAssert(false);
00328     }
00329     return buffered;
00330 }
00331 
00332 inline bool LbmIterableRidReader::hasNext()
00333 {
00334     if (buffered) {
00335         return true;
00336     }
00337     return searchForNextRid();
00338 }
00339 
00340 inline LcsRid LbmIterableRidReader::peek()
00341 {
00342     bool valid = hasNext();
00343     assert(valid);
00344     return bufferedRid;
00345 }
00346 
00347 inline void LbmIterableRidReader::advance()
00348 {
00349     bool valid = hasNext();
00350     assert(valid);
00351     buffered = false;
00352 }
00353 
00354 inline LcsRid LbmIterableRidReader::getNext()
00355 {
00356     LcsRid next = peek();
00357     advance();
00358     return next;
00359 }
00360 
00361 FENNEL_END_NAMESPACE
00362 
00363 #endif
00364 
00365 // End LbmRidReader.h

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