LbmUnionWorkspace Class Reference

The union workspace merges byte segments. More...

#include <LbmUnionWorkspace.h>

List of all members.

Public Member Functions

void init (SharedByteBuffer pBuffer, uint maxSegmentSize)
 Initialize the workspace.
void reset ()
 Empty the workspace.
void advanceToSrid (LcsRid requestedSrid)
 Advance the workspace to the requested Srid.
void advancePastSegment ()
 Advance the workspace past the current workspace segment Precondition is that segment must be set.
void setProductionLimit (LcsRid productionLimitRid)
 Increases the upper bound of production.
void removeLimit ()
 Remove production limit; this allows the workspace to flush its entire contents; no more segments can be added after this call.
bool isEmpty () const
 Whether the workspace is completely empty.
bool canProduce ()
 Whether the workspace is able to produce a segment.
const LbmByteSegmentgetSegment ()
 Returns the current segment.
const LbmByteSegmentgetContiguousSegment ()
 Returns the current contiguous segment.
bool addSegment (const LbmByteSegment &segment)
 Adds a segment to the workspace; the segment must not fall within the current bounds of production.

Private Member Functions

void advanceToByteNum (LbmByteNumber requestedByteNum)
 Advance the workspace to the requested byte number.

Private Attributes

LbmUnionMergeArea mergeArea
 Buffer used to merge segments, indexed by ByteNumber.
uint maxSegmentSize
 Maximum size of a segment that can be produced by this workspace.
bool limited
 Whether there is a limit on production.
LbmByteNumber productionLimitByte
 Byte number of the last byte which can be produced.
LbmByteSegment segment
 A segment that can be returned by the workspace.


Detailed Description

The union workspace merges byte segments.

Author:
John Pham
Version:
Id
//open/dev/fennel/lucidera/bitmap/LbmUnionWorkspace.h#9

Definition at line 39 of file LbmUnionWorkspace.h.


Member Function Documentation

void LbmUnionWorkspace::advanceToByteNum ( LbmByteNumber  requestedByteNum  )  [private]

Advance the workspace to the requested byte number.

Definition at line 49 of file LbmUnionWorkspace.cpp.

References mergeArea, and opaqueToInt().

Referenced by advancePastSegment(), and advanceToSrid().

00050 {
00051     if (opaqueToInt(requestedByteNum) > mergeArea.getStart()) {
00052         mergeArea.advance(opaqueToInt(requestedByteNum));
00053     }
00054 }

void LbmUnionWorkspace::init ( SharedByteBuffer  pBuffer,
uint  maxSegmentSize 
)

Initialize the workspace.

Definition at line 29 of file LbmUnionWorkspace.cpp.

References mergeArea, and reset().

Referenced by LbmUnionExecStream::open().

00030 {
00031     mergeArea.init(pBuffer);
00032     this->maxSegmentSize = maxSegmentSize;
00033     reset();
00034 }

void LbmUnionWorkspace::reset (  ) 

Empty the workspace.

Definition at line 36 of file LbmUnionWorkspace.cpp.

References limited, mergeArea, productionLimitByte, LbmByteSegment::reset(), and segment.

Referenced by init(), and LbmUnionExecStream::open().

00037 {
00038     mergeArea.reset();
00039     segment.reset();
00040     limited = true;
00041     productionLimitByte = (LbmByteNumber) 0;
00042 }

void LbmUnionWorkspace::advanceToSrid ( LcsRid  requestedSrid  ) 

Advance the workspace to the requested Srid.

Definition at line 44 of file LbmUnionWorkspace.cpp.

References advanceToByteNum(), and ridToByteNumber().

Referenced by LbmUnionExecStream::execute(), and LbmUnionExecStream::writeSegment().

00045 {
00046     advanceToByteNum(ridToByteNumber(requestedSrid));
00047 }

void LbmUnionWorkspace::advancePastSegment (  ) 

Advance the workspace past the current workspace segment Precondition is that segment must be set.

Definition at line 56 of file LbmUnionWorkspace.cpp.

References advanceToByteNum(), LbmByteSegment::byteNum, LbmByteSegment::len, and segment.

Referenced by LbmUnionExecStream::transfer().

00057 {
00058     LbmByteNumber endByteNum = segment.byteNum + segment.len;
00059     advanceToByteNum(endByteNum);
00060 }

void LbmUnionWorkspace::setProductionLimit ( LcsRid  productionLimitRid  ) 

Increases the upper bound of production.

This allows the workspace to produce byte segments up to (but not including) the byte containing productionLimitRid. The workspace will not allow a segment to be added within the bounds of production

Definition at line 62 of file LbmUnionWorkspace.cpp.

References limited, productionLimitByte, and ridToByteNumber().

Referenced by LbmUnionExecStream::writeSegment().

00063 {
00064     productionLimitByte = ridToByteNumber(productionLimitRid);
00065     limited = true;
00066 }

void LbmUnionWorkspace::removeLimit (  ) 

Remove production limit; this allows the workspace to flush its entire contents; no more segments can be added after this call.

Definition at line 68 of file LbmUnionWorkspace.cpp.

References limited.

Referenced by LbmUnionExecStream::transferLast().

00069 {
00070     limited = false;
00071 }

bool LbmUnionWorkspace::isEmpty (  )  const

Whether the workspace is completely empty.

Definition at line 73 of file LbmUnionWorkspace.cpp.

References mergeArea.

Referenced by LbmUnionExecStream::execute(), and LbmUnionExecStream::writeSegment().

00074 {
00075     LbmByteNumberPrimitive i;
00076     for (i = mergeArea.getStart(); i < mergeArea.getEnd(); i++) {
00077         if (mergeArea.getByte(i) != 0) {
00078             return false;
00079         }
00080     }
00081     return true;
00082 }

bool LbmUnionWorkspace::canProduce (  ) 

Whether the workspace is able to produce a segment.

Definition at line 84 of file LbmUnionWorkspace.cpp.

References getSegment().

Referenced by LbmUnionExecStream::transfer().

00085 {
00086     return (! getSegment().isNull());
00087 }

const LbmByteSegment & LbmUnionWorkspace::getSegment (  ) 

Returns the current segment.

Definition at line 89 of file LbmUnionWorkspace.cpp.

References LbmByteSegment::byteNum, LbmByteSegment::byteSeg, LbmByteSegment::len, limited, maxSegmentSize, mergeArea, min(), opaqueToInt(), productionLimitByte, LbmByteSegment::reset(), and segment.

Referenced by canProduce(), and LbmUnionExecStream::transfer().

00090 {
00091     // limit for the beginning of a segment; we don't begin a segment
00092     // unless it has had time to mature (grow to maximum size)
00093     LbmByteNumberPrimitive startLimit;
00094 
00095     // limit for reading; we can read to the production limit, but not
00096     // past the end
00097     LbmByteNumberPrimitive readLimit;
00098 
00099     // if production limit is past end of current data, then it can all
00100     // be written out due to the gap in data
00101     LbmByteNumberPrimitive productionLimit = opaqueToInt(productionLimitByte);
00102     if (!limited || (productionLimit > mergeArea.getEnd())) {
00103         startLimit = readLimit = mergeArea.getEnd();
00104     } else {
00105         readLimit = productionLimit;
00106         startLimit = (productionLimit > maxSegmentSize)
00107             ? (productionLimit - maxSegmentSize) : 0;
00108     }
00109 
00110     // begin with a null segment
00111     segment.reset();
00112 
00113     // skip past whitespace
00114     LbmByteNumberPrimitive i = mergeArea.getStart();
00115     while (i < readLimit && mergeArea.getByte(i) == 0) {
00116         i++;
00117     }
00118     mergeArea.advance(i);
00119     LbmByteNumberPrimitive start = i;
00120 
00121     if (start > startLimit) {
00122         return segment;
00123     }
00124 
00125     // find length of segment (only use the contiguous part)
00126     uint len = 0;
00127     while (i < readLimit && mergeArea.getByte(i) != 0) {
00128         i++;
00129         len++;
00130         if (len == maxSegmentSize) {
00131             break;
00132         }
00133     }
00134     uint contigLen;
00135     PBuffer mem = mergeArea.getMem(start, contigLen);
00136     len = std::min(len, contigLen);
00137 
00138     if (len > 0) {
00139         segment.byteNum = LbmByteNumber(start);
00140         segment.byteSeg = mem;
00141         segment.len = len;
00142     }
00143     return segment;
00144 }

const LbmByteSegment& LbmUnionWorkspace::getContiguousSegment (  ) 

Returns the current contiguous segment.

bool LbmUnionWorkspace::addSegment ( const LbmByteSegment segment  ) 

Adds a segment to the workspace; the segment must not fall within the current bounds of production.

Definition at line 146 of file LbmUnionWorkspace.cpp.

References LbmByteSegment::advanceToByteNum(), LbmByteSegment::byteNum, LbmByteSegment::byteSeg, LbmByteSegment::getEnd(), LbmByteSegment::isNull(), LbmByteSegment::len, mergeArea, opaqueToInt(), and segment.

Referenced by LbmUnionExecStream::writeSegment().

00147 {
00148     LbmByteSegment segment = segmentIn;
00149 
00150     // return false if segment cannot fit into merge area
00151     if (opaqueToInt(segment.getEnd()) > mergeArea.getLimit()) {
00152         return false;
00153     }
00154 
00155     // return true if merge area is already advanced beyond segment
00156     if (opaqueToInt(segment.getEnd()) < mergeArea.getStart()) {
00157         return true;
00158     }
00159 
00160     segment.advanceToByteNum(LbmByteNumber(mergeArea.getStart()));
00161     if (! segment.isNull()) {
00162         LbmByteNumberPrimitive next = opaqueToInt(segment.byteNum);
00163         LbmByteNumberPrimitive last = next + segment.len;
00164         PBuffer read = segment.byteSeg;
00165         while (next < last) {
00166             mergeArea.mergeByte(next++, *read--);
00167         }
00168     }
00169     return true;
00170 }


Member Data Documentation

LbmUnionMergeArea LbmUnionWorkspace::mergeArea [private]

Buffer used to merge segments, indexed by ByteNumber.

Definition at line 44 of file LbmUnionWorkspace.h.

Referenced by addSegment(), advanceToByteNum(), getSegment(), init(), isEmpty(), and reset().

uint LbmUnionWorkspace::maxSegmentSize [private]

Maximum size of a segment that can be produced by this workspace.

Definition at line 49 of file LbmUnionWorkspace.h.

Referenced by getSegment().

bool LbmUnionWorkspace::limited [private]

Whether there is a limit on production.

Definition at line 54 of file LbmUnionWorkspace.h.

Referenced by getSegment(), removeLimit(), reset(), and setProductionLimit().

LbmByteNumber LbmUnionWorkspace::productionLimitByte [private]

Byte number of the last byte which can be produced.

Definition at line 59 of file LbmUnionWorkspace.h.

Referenced by getSegment(), reset(), and setProductionLimit().

LbmByteSegment LbmUnionWorkspace::segment [private]

A segment that can be returned by the workspace.

Definition at line 64 of file LbmUnionWorkspace.h.

Referenced by addSegment(), advancePastSegment(), getSegment(), and reset().


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