#include <WinAggHistogramStrA.h>
Public Types | |
typedef WinAggHistogramStrA::_StringDescCompare | StringDescCompare |
typedef multiset< StringDesc, StringDescCompare > | WinAggData |
typedef deque< StringDesc > | WinAggQueue |
Public Member Functions | |
WinAggHistogramStrA () | |
~WinAggHistogramStrA () | |
void | addRow (RegisterRef< char * > *node) |
addRow - Adds new value to tree and updates the running sum for current values. | |
void | dropRow (RegisterRef< char * > *node) |
dropRow - Removes a value from the tree and updates the running sum. | |
void | getMin (RegisterRef< char * > *node) |
getMin - Returns the current MIN() value for the window. | |
void | getMax (RegisterRef< char * > *node) |
getMax - Returns the current MAX() value for the window. | |
void | getFirstValue (RegisterRef< char * > *node) |
getFirstValue - returns the first value which entered the tree | |
void | getLastValue (RegisterRef< char * > *node) |
getLastValue - returns the last value which entered the tree | |
Protected Member Functions | |
void | setReturnReg (RegisterRef< char * > *dest, const StringDesc &src) |
Private Attributes | |
WinAggData | currentWindow |
int64_t | nullRows |
WinAggQueue | queue |
FIFO queue of values, to enable FIRST_VALUE/LAST_VALUE support. | |
Classes | |
struct | _StringDescCompare |
Definition at line 86 of file WinAggHistogramStrA.h.
typedef multiset<StringDesc,StringDescCompare> WinAggHistogramStrA::WinAggData |
Definition at line 113 of file WinAggHistogramStrA.h.
typedef deque<StringDesc> WinAggHistogramStrA::WinAggQueue |
Definition at line 115 of file WinAggHistogramStrA.h.
WinAggHistogramStrA::WinAggHistogramStrA | ( | ) | [inline] |
Definition at line 89 of file WinAggHistogramStrA.h.
00090 : currentWindow(), 00091 nullRows(0), 00092 queue() 00093 {}
WinAggHistogramStrA::~WinAggHistogramStrA | ( | ) | [inline] |
void WinAggHistogramStrA::addRow | ( | RegisterRef< char * > * | node | ) |
addRow - Adds new value to tree and updates the running sum for current values.
Input - New value to be added to the tree
Definition at line 46 of file WinAggHistogramStrA.cpp.
References currentWindow, FixedBuffer, RegisterReference::getBinding(), RegisterRef< TMPLT >::isNull(), nullRows, queue, RegisterRef< TMPLT >::storage(), and RegisterReference::type().
Referenced by add().
00047 { 00048 if (!node->isNull()) { 00049 StringDesc desc; 00050 desc.cbStorage = node->storage(); 00051 desc.mType = node->type(); 00052 desc.pData = new FixedBuffer[desc.cbStorage]; 00053 desc.memCopyFrom(*node->getBinding()); 00054 // printf( 00055 // "WinAggHistogramStrA::addRow cbStorage=%d cbData=%d String=%s\n", 00056 // node->storage(),desc.cbData, desc.pData); 00057 00058 // Insert the value into the window 00059 (void) currentWindow.insert(desc); 00060 00061 // Add to the FIFO queue. Another copy of the StringDesc is 00062 // created, but it points to the same memory. 00063 queue.push_back(desc); 00064 } else { 00065 ++nullRows; 00066 } 00067 }
void WinAggHistogramStrA::dropRow | ( | RegisterRef< char * > * | node | ) |
dropRow - Removes a value from the tree and updates the running sum.
Input - Value to be removed from the tree
Definition at line 69 of file WinAggHistogramStrA.cpp.
References currentWindow, RegisterRef< TMPLT >::isNull(), RegisterRef< TMPLT >::length(), nullRows, RegisterRef< TMPLT >::pointer(), queue, RegisterRef< TMPLT >::storage(), and RegisterReference::type().
Referenced by drop().
00070 { 00071 if (!node->isNull()) { 00072 // create a StringDesc from the node data to supply to the 00073 // search routine 00074 StringDesc desc; 00075 desc.cbStorage = node->storage(); 00076 desc.cbData = node->length(); 00077 desc.mType = node->type(); 00078 desc.pData = reinterpret_cast<PBuffer>(node->pointer()); 00079 // printf( 00080 // "WinAggHistogramStrA::dropRow cbStorage=%d cbData=%d String=%s", 00081 // node->storage(),desc.cbData, desc.pData); 00082 00083 // Search the window for matching entries. It may return more 00084 // than one but we will only delete one. 00085 assert(!currentWindow.empty()); 00086 pair<WinAggData::iterator, WinAggData::iterator> entries = 00087 currentWindow.equal_range(desc); 00088 00089 assert(entries.first != entries.second); // should at least be one 00090 assert(NULL != entries.first->pData); 00091 00092 if (entries.first != entries.second) { 00093 // printf( 00094 // " erasing entry cbStorage=%d cbData=%d String=%s\n", 00095 // entries.first->cbStorage, 00096 // entries.first->cbData, 00097 // entries.first->pData); 00098 if (NULL != entries.first->pData) { 00099 delete [] entries.first->pData; 00100 } 00101 currentWindow.erase(entries.first); 00102 } 00103 00104 // Remove from the FIFO queue. 00105 queue.pop_front(); 00106 } else { 00107 assert(0 != nullRows); 00108 --nullRows; 00109 } 00110 }
void WinAggHistogramStrA::getMin | ( | RegisterRef< char * > * | node | ) |
getMin - Returns the current MIN() value for the window.
Returns NULL if the window is empty.
Definition at line 125 of file WinAggHistogramStrA.cpp.
References currentWindow, setReturnReg(), and RegisterRef< TMPLT >::toNull().
Referenced by min().
00126 { 00127 if (0 != currentWindow.size()) { 00128 setReturnReg(node, *(currentWindow.begin())); 00129 } else { 00130 // either all the rows added to the window had null 00131 // entries or there are no rows in the window. Either 00132 // way the function returns NULL. 00133 node->toNull(); 00134 } 00135 }
void WinAggHistogramStrA::getMax | ( | RegisterRef< char * > * | node | ) |
getMax - Returns the current MAX() value for the window.
Returns NULL if the window is empty.
Definition at line 137 of file WinAggHistogramStrA.cpp.
References currentWindow, setReturnReg(), and RegisterRef< TMPLT >::toNull().
Referenced by max().
00138 { 00139 if (0 != currentWindow.size()) { 00140 setReturnReg(node, *(--(currentWindow.end()))); 00141 } else { 00142 // either all the rows added to the window had null 00143 // entries or there are no rows in the window. Either 00144 // way the function returns NULL. 00145 node->toNull(); 00146 } 00147 }
void WinAggHistogramStrA::getFirstValue | ( | RegisterRef< char * > * | node | ) |
getFirstValue - returns the first value which entered the tree
Returns NULL if the window is empty.
Definition at line 149 of file WinAggHistogramStrA.cpp.
References queue, setReturnReg(), and RegisterRef< TMPLT >::toNull().
Referenced by firstValue().
00150 { 00151 if (queue.empty()) { 00152 node->toNull(); 00153 } else { 00154 setReturnReg(node, queue.front()); 00155 } 00156 }
void WinAggHistogramStrA::getLastValue | ( | RegisterRef< char * > * | node | ) |
getLastValue - returns the last value which entered the tree
Returns NULL if the window is empty.
Definition at line 159 of file WinAggHistogramStrA.cpp.
References queue, setReturnReg(), and RegisterRef< TMPLT >::toNull().
Referenced by lastValue().
00160 { 00161 if (queue.empty()) { 00162 node->toNull(); 00163 } else { 00164 setReturnReg(node, queue.back()); 00165 } 00166 }
void WinAggHistogramStrA::setReturnReg | ( | RegisterRef< char * > * | dest, | |
const StringDesc & | src | |||
) | [protected] |
Definition at line 112 of file WinAggHistogramStrA.cpp.
References RegisterRef< TMPLT >::length(), StringDesc::pointer(), RegisterRef< TMPLT >::pointer(), and StringDesc::stringLength().
Referenced by getFirstValue(), getLastValue(), getMax(), and getMin().
00115 { 00116 char* pData = dest->pointer(); 00117 TupleStorageByteLength srcLength = src.stringLength(); 00118 assert(pData); 00119 assert(srcLength <= dest->storage()); 00120 memcpy(pData, src.pointer(), srcLength); 00121 dest->length(srcLength); 00122 }
WinAggData WinAggHistogramStrA::currentWindow [private] |
int64_t WinAggHistogramStrA::nullRows [private] |
WinAggQueue WinAggHistogramStrA::queue [private] |
FIFO queue of values, to enable FIRST_VALUE/LAST_VALUE support.
Definition at line 159 of file WinAggHistogramStrA.h.
Referenced by addRow(), dropRow(), getFirstValue(), and getLastValue().