00001 /* 00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmMinusExecStream.h#13 $ 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_LbmMinusExecStream_Included 00023 #define Fennel_LbmMinusExecStream_Included 00024 00025 #include "fennel/lucidera/bitmap/LbmBitOpExecStream.h" 00026 #include "fennel/lucidera/bitmap/LbmSeqSegmentReader.h" 00027 #include "fennel/tuple/TupleDataWithBuffer.h" 00028 00029 FENNEL_BEGIN_NAMESPACE 00030 00035 struct LbmMinusExecStreamParams : public LbmBitOpExecStreamParams 00036 { 00037 }; 00038 00058 class FENNEL_LBM_EXPORT LbmMinusExecStream 00059 : public LbmBitOpExecStream 00060 { 00064 bool subtrahendsDone; 00065 00069 bool needToRead; 00070 00074 LcsRid baseRid; 00075 00079 PBuffer baseByteSeg; 00080 00084 uint baseLen; 00085 00089 LcsRid minSubtrahendRid; 00090 00095 LcsRid maxSubtrahendRid; 00096 00101 bool advancePending; 00102 00107 LcsRid advanceSubtrahendRid; 00108 00112 int advanceSubtrahendInputNo; 00113 00114 enum MinusInputType { 00115 UNKNOWN_INPUT = 0, 00116 EMPTY_INPUT, 00117 NONEMPTY_INPUT 00118 }; 00119 00124 MinusInputType inputType; 00125 00130 LbmSeqSegmentReader minuendReader; 00131 00135 bool prevTupleValid; 00136 00140 TupleDataWithBuffer prevTuple; 00141 00145 bool copyPrefixPending; 00146 00150 TupleData prefixedBitmapTuple; 00151 00159 static const uint SUBTRAHEND_BITMAP_SIZE = 32768; 00160 00165 boost::dynamic_bitset<> subtrahendBitmap; 00166 00170 bool needSubtrahendRestart; 00171 00182 ExecStreamResult readMinuendInputAndFlush( 00183 LcsRid &currRid, PBuffer &currByteSeg, uint &currLen); 00184 00188 ExecStreamResult readMinuendInput( 00189 LcsRid &currRid, PBuffer &currByteSeg, uint &currLen); 00190 00191 int comparePrefixes(); 00192 void restartSubtrahends(); 00193 void copyPrefix(); 00194 00203 ExecStreamResult advanceSingleSubtrahend(int inputNo, LcsRid rid); 00204 00212 ExecStreamResult advanceSubtrahends(LcsRid baseRid); 00213 00225 ExecStreamResult minusSegments( 00226 LcsRid baseRid, PBuffer baseByteSeg, uint baseLen); 00227 00238 ExecStreamResult findMinInput(int &minInput); 00239 00263 bool checkNeedForRestart(); 00264 00272 bool canSkipMinus(); 00273 00274 protected: 00275 // override LbmBitOpStream 00276 bool produceTuple(TupleData bitmapTuple); 00277 00278 public: 00279 virtual void prepare(LbmMinusExecStreamParams const ¶ms); 00280 virtual void open(bool restart); 00281 virtual ExecStreamResult execute(ExecStreamQuantum const &quantum); 00282 virtual void closeImpl(); 00283 }; 00284 00285 FENNEL_END_NAMESPACE 00286 00287 #endif 00288 00289 // End LbmMinusExecStream.h