LbmSegmentWriter Class Reference

LbmSegmentWriter constructs a bitmap segment by utilizing LbmEntry to write out individual byte segments. More...

#include <LbmSegmentWriter.h>

List of all members.

Public Member Functions

void init (PBuffer scratchBufferInit, uint scratchBufferSizeInit, TupleDescriptor const &bitmapTupleDesc, bool removeZeros)
 Initializes a new segment writer object.
void reset ()
 Resets a segment writer object to start writing out a new bitmap segment.
bool isEmpty ()
 Returns whether the segment writer has added any segments.
bool addSegment (LcsRid &startRid, PBuffer &pByteSeg, uint &len)
 Adds a new byte segment to the bitmap segment under construction.
TupleData const & produceSegmentTuple ()
 Produces the current segment constructed thus far in tupledata format.

Private Attributes

LbmEntry segmentEntry
 Bitmap entry object used to construct bitmap segments.
TupleData bitmapTuple
 Tuple data used to pass byte segments to LbmEntry.
bool firstWrite
 True if no byte segments have been written yet.
bool removeZeros
 True if zeros should be removed from the bitmap segments.


Detailed Description

LbmSegmentWriter constructs a bitmap segment by utilizing LbmEntry to write out individual byte segments.

A bitmap segment is a bitmap entry with no leading index key values.

Definition at line 34 of file LbmSegmentWriter.h.


Member Function Documentation

void LbmSegmentWriter::init ( PBuffer  scratchBufferInit,
uint  scratchBufferSizeInit,
TupleDescriptor const &  bitmapTupleDesc,
bool  removeZeros 
)

Initializes a new segment writer object.

Parameters:
scratchBufferInit scratch buffer for constructing bitmap segments
scratchBufferSizeInit size of scratch buffer
bitmapTupleDesc descriptor of the tuple that will represent the constructed bitmap segment
removeZeros true if zeros should be removed before writing out segments; should only be true in cases like intersection where it is possible to have zeros; whereas, union should not

Definition at line 27 of file LbmSegmentWriter.cpp.

References bitmapTuple, TupleData::compute(), LbmEntry::init(), removeZeros, reset(), and segmentEntry.

Referenced by LbmUnionExecStream::open(), LbmChopperExecStream::open(), and LbmBitOpExecStream::open().

00031 {
00032     segmentEntry.init(
00033         scratchBufferInit, NULL, scratchBufferSizeInit, bitmapTupleDesc);
00034     bitmapTuple.compute(bitmapTupleDesc);
00035     removeZeros = removeZerosInit;
00036     reset();
00037 }

void LbmSegmentWriter::reset (  ) 

Resets a segment writer object to start writing out a new bitmap segment.

Definition at line 39 of file LbmSegmentWriter.cpp.

References firstWrite.

Referenced by LbmBitOpExecStream::addSegments(), LbmBitOpExecStream::flush(), init(), LbmUnionExecStream::open(), LbmChopperExecStream::open(), LbmBitOpExecStream::open(), LbmBitOpExecStream::producePendingOutput(), LbmUnionExecStream::produceTuple(), and LbmChopperExecStream::produceTuple().

00040 {
00041     firstWrite = true;
00042 }

bool LbmSegmentWriter::isEmpty (  ) 

Returns whether the segment writer has added any segments.

Definition at line 44 of file LbmSegmentWriter.cpp.

References firstWrite.

Referenced by LbmUnionExecStream::execute(), LbmChopperExecStream::execute(), LbmBitOpExecStream::flush(), LbmBitOpExecStream::producePendingOutput(), LbmUnionExecStream::produceTuple(), and LbmChopperExecStream::writeSegment().

00045 {
00046     return firstWrite;
00047 }

bool LbmSegmentWriter::addSegment ( LcsRid &  startRid,
PBuffer pByteSeg,
uint len 
)

Adds a new byte segment to the bitmap segment under construction.

Removes zeros if specified during intialization.

Parameters:
startRid starting rid of segment
pByteSeg pointer to the last byte segment in a segment that is stored backwards
len length of the byte segment
Returns:
false if not enough space to add the new segment, in which case startRid, pByteSeg, and len represent the remaining portions of the segment that have not been written out yet

Definition at line 49 of file LbmSegmentWriter.cpp.

References bitmapTuple, firstWrite, LbmSegment::LbmOneByteSize, LbmEntry::mergeEntry(), removeZeros, segmentEntry, LbmEntry::setEntryTuple(), and LbmSegment::setSegLength().

Referenced by LbmBitOpExecStream::addSegments(), LbmUnionExecStream::transfer(), and LbmChopperExecStream::writeSegment().

00051 {
00052     uint8_t segDescByte;
00053 
00054     if (removeZeros) {
00055         // remove trailing zeros; note that they're trailing because the
00056         // segments in pByteSeg are backwards
00057         while (len > 0 && *pByteSeg == 0) {
00058             pByteSeg++;
00059             len--;
00060         }
00061 
00062         // remove leading zeros
00063         PBuffer bufPtr = pByteSeg + len - 1;
00064         while (len > 0 && *bufPtr == 0) {
00065             bufPtr--;
00066             len--;
00067             startRid += LbmSegment::LbmOneByteSize;
00068         }
00069     }
00070 
00071     while (len > 0) {
00072         // determine if there are any intermediate zeros
00073         uint subLen;
00074         if (!removeZeros) {
00075             subLen = len;
00076         } else {
00077             for (subLen = 0; subLen < len; subLen++) {
00078                 if (pByteSeg[len - 1 - subLen] == 0) {
00079                     break;
00080                 }
00081             }
00082         }
00083 
00084         // write out the first set of segments up to the first intermediate
00085         // zero, if there is one; otherwise, we just end up writing out
00086         // all of the segments passed in
00087 
00088         bitmapTuple[0].pData = (PConstBuffer) &startRid;
00089         // if the length can't be encoded in a segment descriptor, then
00090         // we have to treat this bitmap as a single bitmap
00091         if (LbmSegment::setSegLength(segDescByte, subLen)) {
00092             bitmapTuple[1].pData = &segDescByte;
00093             bitmapTuple[1].cbData = 1;
00094         } else {
00095             bitmapTuple[1].pData = NULL;
00096             bitmapTuple[1].cbData = 0;
00097         }
00098         bitmapTuple[2].pData = pByteSeg + len - subLen;
00099         bitmapTuple[2].cbData = subLen;
00100 
00101         if (firstWrite) {
00102             segmentEntry.setEntryTuple(bitmapTuple);
00103             firstWrite = false;
00104         } else {
00105             if (!segmentEntry.mergeEntry(bitmapTuple)) {
00106                 return false;
00107             }
00108         }
00109 
00110         if (subLen == len) {
00111             break;
00112         }
00113 
00114         // figure out how many more intermediate zeros there are
00115         while (pByteSeg[len - 1 - subLen] == 0) {
00116             subLen++;
00117         }
00118 
00119         // adjust the next segment forward, past the intermediate zeros
00120         startRid += subLen * LbmSegment::LbmOneByteSize;
00121         len -= subLen;
00122     }
00123 
00124     return true;
00125 }

TupleData const & LbmSegmentWriter::produceSegmentTuple (  ) 

Produces the current segment constructed thus far in tupledata format.

Returns:
a pointer to the bitmap segment

Definition at line 127 of file LbmSegmentWriter.cpp.

References LbmEntry::produceEntryTuple(), and segmentEntry.

Referenced by LbmBitOpExecStream::addSegments(), LbmBitOpExecStream::flush(), LbmUnionExecStream::produceTuple(), and LbmChopperExecStream::produceTuple().

00128 {
00129     return segmentEntry.produceEntryTuple();
00130 }


Member Data Documentation

LbmEntry LbmSegmentWriter::segmentEntry [private]

Bitmap entry object used to construct bitmap segments.

Definition at line 40 of file LbmSegmentWriter.h.

Referenced by addSegment(), init(), and produceSegmentTuple().

TupleData LbmSegmentWriter::bitmapTuple [private]

Tuple data used to pass byte segments to LbmEntry.

Definition at line 45 of file LbmSegmentWriter.h.

Referenced by addSegment(), and init().

bool LbmSegmentWriter::firstWrite [private]

True if no byte segments have been written yet.

Definition at line 50 of file LbmSegmentWriter.h.

Referenced by addSegment(), isEmpty(), and reset().

bool LbmSegmentWriter::removeZeros [private]

True if zeros should be removed from the bitmap segments.

Definition at line 55 of file LbmSegmentWriter.h.

Referenced by addSegment(), and init().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:36 2009 for Fennel by  doxygen 1.5.1