00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "fennel/common/CommonPreamble.h"
00023 #include "fennel/exec/ExecStreamBufAccessor.h"
00024 #include "fennel/lucidera/bitmap/LbmSegmentReader.h"
00025 #include "fennel/lucidera/bitmap/LbmTupleReader.h"
00026
00027 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSegmentReaderBase.cpp#9 $");
00028
00029 void LbmSegmentReaderBase::init(
00030 SharedExecStreamBufAccessor &pInAccessorInit,
00031 TupleData &bitmapSegTuple)
00032 {
00033 LbmStreamTupleReader *pNewReader = new LbmStreamTupleReader();
00034 pNewReader->init(pInAccessorInit, bitmapSegTuple);
00035 SharedLbmTupleReader pTupleReader(pNewReader);
00036 init(pTupleReader, bitmapSegTuple, false, NULL);
00037 }
00038
00039 void LbmSegmentReaderBase::init(
00040 SharedExecStreamBufAccessor &pInAccessorInit,
00041 TupleData &bitmapSegTuple,
00042 bool setBitmapInit,
00043 boost::dynamic_bitset<> *pBitmapInit)
00044 {
00045 LbmStreamTupleReader *pNewReader = new LbmStreamTupleReader();
00046 pNewReader->init(pInAccessorInit, bitmapSegTuple);
00047 SharedLbmTupleReader pTupleReader(pNewReader);
00048 init(pTupleReader, bitmapSegTuple, setBitmapInit, pBitmapInit);
00049 }
00050
00051 void LbmSegmentReaderBase::init(
00052 SharedLbmTupleReader &pTupleReaderInit,
00053 TupleData &bitmapSegTuple)
00054 {
00055 init(pTupleReaderInit, bitmapSegTuple, false, NULL);
00056 }
00057
00058 void LbmSegmentReaderBase::init(
00059 SharedLbmTupleReader &pTupleReaderInit,
00060 TupleData &bitmapSegTuple,
00061 bool setBitmapInit,
00062 boost::dynamic_bitset<> *pBitmapInit)
00063 {
00064 pTupleReader = pTupleReaderInit;
00065 pBitmapSegTuple = &bitmapSegTuple;
00066 iSrid = bitmapSegTuple.size() - 3;
00067 iSegmentDesc = iSrid + 1;
00068 iSegments = iSrid + 2;
00069 byteSegLen = 0;
00070 byteSegOffset = LbmByteNumber(0);
00071 pSegStart = NULL;
00072 pSegDescStart = NULL;
00073 pSegDescEnd = NULL;
00074 zeroBytes = 0;
00075 tupleChange = false;
00076 setBitmap = setBitmapInit;
00077 pBitmap = pBitmapInit;
00078 maxRidSet = LcsRid(0);
00079 }
00080
00081 ExecStreamResult LbmSegmentReaderBase::readBitmapSegTuple()
00082 {
00083 ExecStreamResult rc = pTupleReader->read(pBitmapSegTuple);
00084 if (rc != EXECRC_YIELD) {
00085 return rc;
00086 }
00087
00088
00089 startRID = *reinterpret_cast<LcsRid const *>
00090 ((*pBitmapSegTuple)[iSrid].pData);
00091 byteSegOffset = ridToByteNumber(startRID);
00092 zeroBytes = 0;
00093
00094
00095
00096 pSegDescStart = (PBuffer) (*pBitmapSegTuple)[iSegmentDesc].pData;
00097
00098 if (pSegDescStart != NULL) {
00099 pSegDescEnd = pSegDescStart + (*pBitmapSegTuple)[iSegmentDesc].cbData;
00100 } else {
00101 pSegDescEnd = NULL;
00102 }
00103
00104
00105 if ((*pBitmapSegTuple)[iSegments].pData) {
00106
00107 byteSegLen = (*pBitmapSegTuple)[iSegments].cbData;
00108 pSegStart = (PBuffer)
00109 ((*pBitmapSegTuple)[iSegments].pData + byteSegLen - 1);
00110 } else {
00111
00112 byteSegLen = 1;
00113 pSegStart = &singleton;
00114 singleton = (uint8_t)(1 << (opaqueToInt(startRID) % LbmOneByteSize));
00115 if (setBitmap) {
00116 pBitmap->set(opaqueToInt(startRID % pBitmap->size()));
00117 if (startRID > maxRidSet) {
00118 maxRidSet = startRID;
00119 }
00120 }
00121 }
00122
00123 if (!pSegDescStart) {
00124
00125
00126
00127 setBitsRead(startRID, pSegStart, byteSegLen);
00128 }
00129
00130 tupleChange = true;
00131 return EXECRC_YIELD;
00132 }
00133
00134 void LbmSegmentReaderBase::setBitsRead(
00135 LcsRid startRid,
00136 PBuffer segStart,
00137 uint segLen)
00138 {
00139 if (setBitmap) {
00140 uint bitmapSize = pBitmap->size();
00141 PBuffer seg = segStart;
00142 LcsRid rid = startRid;
00143 for (uint i = 0; i < segLen; i++) {
00144 uint8_t byte = *(uint8_t *) seg;
00145 for (uint j = 0; j < LbmOneByteSize; j++) {
00146 if (byte & 1) {
00147 pBitmap->set(opaqueToInt(rid % bitmapSize));
00148 if (rid > maxRidSet) {
00149 maxRidSet = rid;
00150 }
00151 }
00152 byte = byte >> 1;
00153 rid++;
00154 }
00155 seg--;
00156 }
00157 }
00158 }
00159
00160 void LbmSegmentReaderBase::advanceSegment()
00161 {
00162
00163
00164
00165 byteSegOffset += byteSegLen + zeroBytes;
00166 pSegStart -= byteSegLen;
00167
00168
00169
00170
00171 readSegDescAndAdvance(pSegDescStart, byteSegLen, zeroBytes);
00172
00173
00174 setBitsRead(byteNumberToRid(byteSegOffset), pSegStart, byteSegLen);
00175 }
00176
00177 bool LbmSegmentReaderBase::getTupleChange()
00178 {
00179 return tupleChange;
00180 }
00181
00182 void LbmSegmentReaderBase::resetChangeListener()
00183 {
00184 tupleChange = false;
00185 }
00186
00187 LcsRid LbmSegmentReaderBase::getMaxRidSet()
00188 {
00189 return maxRidSet;
00190 }
00191
00192 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSegmentReaderBase.cpp#9 $");
00193
00194