LhxHashDataAccessor Class Reference

#include <LhxHashTable.h>

Inheritance diagram for LhxHashDataAccessor:

LhxHashNodeAccessor List of all members.

Public Member Functions

 LhxHashDataAccessor ()
void init (TupleDescriptor const &inputDataDesc)
 Set the shape of the data tuple to be stored via this accessor.
void setCurrent (PBuffer nodePtrInit, bool valid)
 Set the current node pointer for this accessor.
uint getAvgStorageSize ()
 Get the avg buffer size required to store all the fields based on TupleDescriptor information previously passed in init().
uint getStorageSize (TupleData const &inputTuple)
 Get actual buffer size required to store all the fields.
uint getDiskStorageSize (TupleData const &inputTuple)
 Get actual disk size required to store all the fields.
void checkStorageSize (TupleData const &inputTuple, uint maxBufferSize)
 Check that buffer size required to store all the fields does not exceed scratch buffer size.
void pack (TupleData const &inputTuple)
 Store a tuple in the buffer associated with this accessor.
void unpack (TupleData &outputTuple, TupleProjection &destProj)
 Retrieve the data stored in the buffer.
string toString ()
 Print the content of the node associated with this accessor.
PBuffer getCurrent ()
 
Returns:
current node associated with this accessor

void setCurrent (PBuffer nodePtrInit)
 Set the current node pointer for this accessor.
void reset ()
 Reset the node pointer to NULL.
PBuffer getBuffer ()
 
Returns:
buffer to the payload in this node

PBuffer getNext ()
 
Returns:
the next node

PBuffer getNextLocation ()
 
Returns:
the location which stores the next node pointer

void setNext (PBuffer nextNode)
 Set the next node pointer for node associated with this accessor.
void setNext (PBuffer inputNode, PBuffer nextNode)
 Set the next node pointer for an input node.
uint getNextFieldSize ()
 
Returns:
number of bytes required to store the next node pointer

uint getBufferOffset ()
 
Returns:
offset to the .


Private Attributes

TupleDescriptor dataDescriptor
TupleData dataTuple
TupleAccessor dataAccessor

Detailed Description

Definition at line 158 of file LhxHashTable.h.


Constructor & Destructor Documentation

LhxHashDataAccessor::LhxHashDataAccessor (  )  [inline]

Definition at line 177 of file LhxHashTable.h.

00177 : LhxHashNodeAccessor() {}


Member Function Documentation

void LhxHashDataAccessor::init ( TupleDescriptor const &  inputDataDesc  ) 

Set the shape of the data tuple to be stored via this accessor.

Parameters:
[in] inputDataDesc 

Definition at line 33 of file LhxHashTable.cpp.

References TupleAccessor::compute(), TupleData::compute(), dataAccessor, dataDescriptor, and dataTuple.

Referenced by LhxHashTable::calculateSize(), LhxHashTableReader::init(), and LhxHashTable::init().

00034 {
00035     dataDescriptor = inputDataDesc;
00036     dataTuple.compute(dataDescriptor);
00037     dataAccessor.compute(dataDescriptor);
00038 }

void LhxHashDataAccessor::setCurrent ( PBuffer  nodePtrInit,
bool  valid 
) [inline]

Set the current node pointer for this accessor.

Parameters:
[in] nodePtrInit pointer to node that will be associated with this accessor
[in] valid whether buffer content is valid.

Definition at line 1111 of file LhxHashTable.h.

References dataAccessor, LhxHashNodeAccessor::getBuffer(), LhxHashNodeAccessor::setCurrent(), and TupleAccessor::setCurrentTupleBuf().

Referenced by LhxHashTable::addData(), LhxHashTable::addKeyData(), LhxHashTableReader::advanceData(), LhxHashTableReader::advanceKey(), LhxHashTableReader::advanceSlot(), and LhxHashTable::printSlot().

01112 {
01113     LhxHashNodeAccessor::setCurrent(nodePtrInit);
01114     dataAccessor.setCurrentTupleBuf(getBuffer(), valid);
01115 }

uint LhxHashDataAccessor::getAvgStorageSize (  )  [inline]

Get the avg buffer size required to store all the fields based on TupleDescriptor information previously passed in init().

This function needs to be called after calling init().

Definition at line 1117 of file LhxHashTable.h.

References dataAccessor, LhxHashNodeAccessor::getBufferOffset(), TupleAccessor::getMaxByteCount(), and TupleAccessor::getMinByteCount().

Referenced by LhxHashTable::calculateSize().

01118 {
01119     // compute the average based on the min and max
01120     // TODO - use stats to compute a more realistic average
01121     return
01122         ((dataAccessor.getMaxByteCount() +
01123             dataAccessor.getMinByteCount()) / 2) +
01124         getBufferOffset();
01125 }

uint LhxHashDataAccessor::getStorageSize ( TupleData const &  inputTuple  )  [inline]

Get actual buffer size required to store all the fields.

Parameters:
[in] inputTuple get the storage size for this inputTuple.

Definition at line 1127 of file LhxHashTable.h.

References dataAccessor, LhxHashNodeAccessor::getBufferOffset(), and TupleAccessor::getByteCount().

Referenced by LhxHashTable::addData(), LhxHashTable::addKeyData(), and checkStorageSize().

01128 {
01129     return dataAccessor.getByteCount(inputTuple) + getBufferOffset();
01130 }

uint LhxHashDataAccessor::getDiskStorageSize ( TupleData const &  inputTuple  )  [inline]

Get actual disk size required to store all the fields.

Parameters:
[in] inputTuple get the storage size for this inputTuple.

Definition at line 1132 of file LhxHashTable.h.

References dataAccessor, and TupleAccessor::getByteCount().

01134 {
01135     return dataAccessor.getByteCount(inputTuple);
01136 }

void LhxHashDataAccessor::checkStorageSize ( TupleData const &  inputTuple,
uint  maxBufferSize 
) [inline]

Check that buffer size required to store all the fields does not exceed scratch buffer size.

Parameters:
[in] inputTuple if NULL get the tuple storage size for the buffer associated with this accessor; else get the storage size for the inputTuple.
[in] maxBufferSize maximum buffer size

Definition at line 1138 of file LhxHashTable.h.

References dataDescriptor, and getStorageSize().

Referenced by LhxHashTable::addData(), and LhxHashTable::addKeyData().

01141 {
01142     uint storageSize = getStorageSize(inputTuple);
01143 
01144     if (storageSize > maxBufferSize) {
01145         throw TupleOverflowExcn(
01146             dataDescriptor,
01147             inputTuple,
01148             storageSize,
01149             maxBufferSize);
01150     }
01151 }

void LhxHashDataAccessor::pack ( TupleData const &  inputTuple  )  [inline]

Store a tuple in the buffer associated with this accessor.

Parameters:
[in] inputTuple 

Definition at line 1165 of file LhxHashTable.h.

References dataAccessor, LhxHashNodeAccessor::getBuffer(), TupleAccessor::marshal(), and TupleAccessor::size().

Referenced by LhxHashTable::addData(), and LhxHashTable::addKeyData().

01167 {
01168     PBuffer buf = getBuffer();
01169 
01170     assert(buf != NULL && inputTuple.size() == dataAccessor.size());
01171 
01172     /*
01173      * Copy the input tuple into the buffer associated with this accessor.
01174      */
01175     dataAccessor.marshal(inputTuple, buf);
01176 }

void LhxHashDataAccessor::unpack ( TupleData outputTuple,
TupleProjection destProj 
)

Retrieve the data stored in the buffer.

Upon return, outputTuple will point into the buffer associated with this accessor.

Parameters:
[out] outputTuple 
[out] destProj fields to copy to in the outputTuple

Definition at line 40 of file LhxHashTable.cpp.

References dataAccessor, dataTuple, LhxHashNodeAccessor::getBuffer(), min(), and TupleAccessor::unmarshal().

Referenced by LhxHashTableReader::produceTuple(), and toString().

00043 {
00044     PBuffer buf = getBuffer();
00045 
00046     assert (buf != NULL);
00047 
00048     if (destProj.size() > 0) {
00049         // REVIEW jvs 25-Aug-2006:  It looks like there's a potential
00050         // for unmarshalling unneeded fields here.  If there could
00051         // be a lot of those, set up a TupleProjectionAccessor
00052         // and use that (over and over) instead.
00053 
00054         /*
00055          * Destination positions in the outputTuple should be enough to hold
00056          * fields returned by dataAccessor.
00057          */
00058         uint tupleSize = min(destProj.size(), dataTuple.size());
00059 
00060         /*
00061          * Set pointers in the tmp tuple, and then pass them on to fields in
00062          * output tuple.
00063          */
00064         dataAccessor.unmarshal(dataTuple);
00065 
00066         for (int i = 0; i < tupleSize; i ++) {
00067             outputTuple[destProj[i]].copyFrom(dataTuple[i]);
00068         }
00069     } else {
00070         /*
00071          * Set pointers in the outputTuple.
00072          */
00073         dataAccessor.unmarshal(outputTuple);
00074     }
00075 }

string LhxHashDataAccessor::toString (  ) 

Print the content of the node associated with this accessor.

Definition at line 77 of file LhxHashTable.cpp.

References dataDescriptor, dataTuple, TuplePrinter::print(), and unpack().

Referenced by LhxHashTable::printSlot().

00078 {
00079     TuplePrinter tuplePrinter;
00080     ostringstream dataTrace;
00081     TupleProjection allFields;
00082     allFields.clear();
00083 
00084     unpack(dataTuple, allFields);
00085     dataTrace << "[Data Node] ";
00086     tuplePrinter.print(dataTrace, dataDescriptor, dataTuple);
00087     return dataTrace.str();
00088 }

PBuffer LhxHashNodeAccessor::getCurrent (  )  [inline, inherited]

Returns:
current node associated with this accessor

Definition at line 1051 of file LhxHashTable.h.

References LhxHashNodeAccessor::nodePtr.

Referenced by LhxHashKeyAccessor::getFirstData(), LhxHashKeyAccessor::getNextSlot(), LhxHashBlockAccessor::getSlot(), LhxHashKeyAccessor::isMatched(), LhxHashKeyAccessor::setFirstData(), LhxHashKeyAccessor::setMatched(), and LhxHashKeyAccessor::setNextSlot().

01052 {
01053     return nodePtr;
01054 }

void LhxHashNodeAccessor::setCurrent ( PBuffer  nodePtrInit  )  [inline, inherited]

Set the current node pointer for this accessor.

Parameters:
[in] nodePtrInit pointer to node that will be associated with this accessor

Definition at line 1061 of file LhxHashTable.h.

References LhxHashNodeAccessor::nodePtr.

Referenced by LhxHashNodeAccessor::reset(), LhxHashKeyAccessor::setCurrent(), setCurrent(), and LhxHashBlockAccessor::setCurrent().

01062 {
01063     nodePtr = nodePtrInit;
01064 }

void LhxHashNodeAccessor::reset (  )  [inline, inherited]

Reset the node pointer to NULL.

Reimplemented in LhxHashBlockAccessor.

Definition at line 1066 of file LhxHashTable.h.

References LhxHashNodeAccessor::setCurrent().

Referenced by LhxHashTable::releaseResources(), and LhxHashBlockAccessor::reset().

01067 {
01068     setCurrent(NULL);
01069 }

PBuffer LhxHashNodeAccessor::getBuffer (  )  [inline, inherited]

Returns:
buffer to the payload in this node

Definition at line 1056 of file LhxHashTable.h.

References LhxHashNodeAccessor::nodeBufferOffset, and LhxHashNodeAccessor::nodePtr.

Referenced by LhxHashBlockAccessor::getSlot(), pack(), LhxHashKeyAccessor::pack(), LhxHashKeyAccessor::setCurrent(), setCurrent(), LhxHashBlockAccessor::setCurrent(), LhxHashKeyAccessor::unpack(), and unpack().

01057 {
01058     return (nodePtr + nodeBufferOffset);
01059 }

PBuffer LhxHashNodeAccessor::getNext (  )  [inline, inherited]

Returns:
the next node

Definition at line 1071 of file LhxHashTable.h.

References LhxHashNodeAccessor::nextNodeOffset, and LhxHashNodeAccessor::nodePtr.

Referenced by LhxHashTableReader::advanceData(), LhxHashTableReader::advanceKey(), LhxHashTableReader::advanceSlot(), LhxHashTable::aggData(), LhxHashTable::allocateResources(), LhxHashTable::allocBuffer(), LhxHashTable::findKeyLocation(), and LhxHashTable::printSlot().

01072 {
01073     // REVIEW jvs 25-Aug-2006:  Under what circumstances would
01074     // alignment be off?  Tuple sizes are always aligned.  Is it
01075     // because of the match indicator?  If so, it might make sense to
01076     // fold that into the tuple.
01077     /*
01078      * nodePtr+nextNodeOffset might not be aligned so copy the pointer
01079      * value out.
01080      */
01081     PBuffer returnPtr;
01082     memcpy((PBuffer)&returnPtr, nodePtr+nextNodeOffset, sizeof(PBuffer));
01083     return returnPtr;
01084 }

PBuffer LhxHashNodeAccessor::getNextLocation (  )  [inline, inherited]

Returns:
the location which stores the next node pointer

Definition at line 1086 of file LhxHashTable.h.

References LhxHashNodeAccessor::nextNodeOffset, and LhxHashNodeAccessor::nodePtr.

Referenced by LhxHashTable::findKeyLocation().

01087 {
01088     return nodePtr + nextNodeOffset;
01089 }

void LhxHashNodeAccessor::setNext ( PBuffer  nextNode  )  [inline, inherited]

Set the next node pointer for node associated with this accessor.

Parameters:
[in] nextNode pointer to the next node

Definition at line 1091 of file LhxHashTable.h.

References LhxHashNodeAccessor::getNextFieldSize(), LhxHashNodeAccessor::nextNodeOffset, and LhxHashNodeAccessor::nodePtr.

Referenced by LhxHashKeyAccessor::addData(), LhxHashTable::addKeyData(), LhxHashTable::aggData(), LhxHashTable::allocateResources(), LhxHashTable::allocBlock(), and LhxHashTable::allocBuffer().

01092 {
01093     memcpy(nodePtr+nextNodeOffset, (PBuffer)&nextNode, getNextFieldSize());
01094 }

void LhxHashNodeAccessor::setNext ( PBuffer  inputNode,
PBuffer  nextNode 
) [inline, inherited]

Set the next node pointer for an input node.

Parameters:
[in] inputNode input node to set the next node pointer
[in] nextNode pointer to the next node

Definition at line 1096 of file LhxHashTable.h.

References LhxHashNodeAccessor::getNextFieldSize(), and LhxHashNodeAccessor::nextNodeOffset.

01097 {
01098     memcpy(inputNode+nextNodeOffset, (PBuffer)&nextNode, getNextFieldSize());
01099 }

uint LhxHashNodeAccessor::getNextFieldSize (  )  [inline, inherited]

Returns:
number of bytes required to store the next node pointer

Definition at line 1101 of file LhxHashTable.h.

Referenced by LhxHashNodeAccessor::LhxHashNodeAccessor(), and LhxHashNodeAccessor::setNext().

01102 {
01103     return sizeof(PBuffer);
01104 }

uint LhxHashNodeAccessor::getBufferOffset (  )  [inline, inherited]

Returns:
offset to the .

This is equivalent to the total space used for the variable length payload.

Definition at line 1106 of file LhxHashTable.h.

References LhxHashNodeAccessor::nodeBufferOffset.

Referenced by LhxHashKeyAccessor::getAvgStorageSize(), getAvgStorageSize(), LhxHashKeyAccessor::getStorageSize(), getStorageSize(), and LhxHashBlockAccessor::init().

01107 {
01108     return nodeBufferOffset;
01109 }


Member Data Documentation

TupleDescriptor LhxHashDataAccessor::dataDescriptor [private]

Definition at line 164 of file LhxHashTable.h.

Referenced by checkStorageSize(), init(), and toString().

TupleData LhxHashDataAccessor::dataTuple [private]

Definition at line 169 of file LhxHashTable.h.

Referenced by init(), toString(), and unpack().

TupleAccessor LhxHashDataAccessor::dataAccessor [private]

Definition at line 174 of file LhxHashTable.h.

Referenced by getAvgStorageSize(), getDiskStorageSize(), getStorageSize(), init(), pack(), setCurrent(), and unpack().


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