#include <WinAggHistogram.h>
Public Types | |
typedef multiset< STDTYPE > | WinAggData |
typedef list< STDTYPE > | WinAggQueue |
Public Member Functions | |
WinAggHistogram () | |
~WinAggHistogram () | |
void | addRow (RegisterRef< STDTYPE > *node) |
addRow - Adds new value to tree and updates the running sum for current values. | |
void | dropRow (RegisterRef< STDTYPE > *node) |
dropRow - Removes a value from the tree and updates the running sum. | |
void | getMin (RegisterRef< STDTYPE > *node) |
getMin - Returns the current MIN() value for the window. | |
void | getMax (RegisterRef< STDTYPE > *node) |
getMax - Returns the current MAX() value for the window. | |
void | getSum (RegisterRef< STDTYPE > *node) |
getSum - return the current sum for all values in the window. | |
void | getCount (RegisterRef< int64_t > *node) |
getCount - returns the current number of entries in the window | |
void | getAvg (RegisterRef< STDTYPE > *node) |
getAvg - calculates and returns the average over the values currently in the tree. | |
void | getFirstValue (RegisterRef< STDTYPE > *node) |
getFirstValue - returns the first value which entered the tree | |
void | getLastValue (RegisterRef< STDTYPE > *node) |
getLastValue - returns the last value which entered the tree | |
Private Attributes | |
WinAggData | currentWindow |
int64_t | nullRows |
STDTYPE | currentSum |
Holds the running sum over the window. | |
WinAggQueue | queue |
FIFO queue of values, to enable FIRST_VALUE/LAST_VALUE support. |
Each row entry is held in a tree structure to make finding new min/max functions easy as values are added/removed from the window. Running sum is also kept up to date as rows enter and exit the window.
It is provided as a parameter to all windowed agg support functions.
Definition at line 55 of file WinAggHistogram.h.
typedef multiset<STDTYPE> WinAggHistogram< STDTYPE >::WinAggData |
Definition at line 69 of file WinAggHistogram.h.
typedef list<STDTYPE> WinAggHistogram< STDTYPE >::WinAggQueue |
Definition at line 73 of file WinAggHistogram.h.
WinAggHistogram< STDTYPE >::WinAggHistogram | ( | ) | [inline] |
Definition at line 59 of file WinAggHistogram.h.
00060 : currentWindow(), 00061 nullRows(0), 00062 currentSum(0), 00063 queue() 00064 {}
WinAggHistogram< STDTYPE >::~WinAggHistogram | ( | ) | [inline] |
void WinAggHistogram< STDTYPE >::addRow | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
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 80 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::currentSum, WinAggHistogram< STDTYPE >::currentWindow, RegisterRef< TMPLT >::isNull(), WinAggHistogram< STDTYPE >::nullRows, WinAggHistogram< STDTYPE >::queue, and RegisterRef< TMPLT >::value().
Referenced by add().
00081 { 00082 // Add the new node to the histogram strucuture 00083 00084 if (!node->isNull()) { 00085 STDTYPE val = node->value(); 00086 (void) currentWindow.insert(val); 00087 currentSum += val; 00088 00089 // Add to the FIFO queue. 00090 queue.push_back(val); 00091 00092 } else { 00093 ++nullRows; 00094 } 00095 }
void WinAggHistogram< STDTYPE >::dropRow | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
dropRow - Removes a value from the tree and updates the running sum.
Input - Value to be removed from the tree
Definition at line 102 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::currentSum, WinAggHistogram< STDTYPE >::currentWindow, RegisterRef< TMPLT >::isNull(), WinAggHistogram< STDTYPE >::nullRows, WinAggHistogram< STDTYPE >::queue, and RegisterRef< TMPLT >::refer().
Referenced by drop().
00103 { 00104 if (!node->isNull()) { 00105 assert(0 != currentWindow.size()); 00106 STDTYPE* pData = node->refer(); 00107 00108 pair< 00109 typename WinAggData::iterator, 00110 typename WinAggData::iterator> entries = 00111 currentWindow.equal_range(*pData); 00112 00113 assert(entries.first != entries.second); 00114 if (entries.first != entries.second) { 00115 currentWindow.erase(entries.first); 00116 currentSum -= *pData; 00117 } 00118 00119 // Remove from the FIFO queue. 00120 queue.pop_front(); 00121 } else { 00122 assert(0 != nullRows); 00123 --nullRows; 00124 } 00125 }
void WinAggHistogram< STDTYPE >::getMin | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
getMin - Returns the current MIN() value for the window.
Returns NULL if the window is empty.
Definition at line 130 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::currentWindow, RegisterRef< TMPLT >::toNull(), and RegisterRef< TMPLT >::value().
Referenced by min().
00131 { 00132 if (0 != currentWindow.size()) { 00133 node->value(*(currentWindow.begin())); 00134 } else { 00135 node->toNull(); 00136 } 00137 }
void WinAggHistogram< STDTYPE >::getMax | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
getMax - Returns the current MAX() value for the window.
Returns NULL if the window is empty.
Definition at line 142 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::currentWindow, RegisterRef< TMPLT >::toNull(), and RegisterRef< TMPLT >::value().
Referenced by max().
00143 { 00144 if (0 != currentWindow.size()) { 00145 node->value(*(--(currentWindow.end()))); 00146 } else { 00147 node->toNull(); 00148 } 00149 }
void WinAggHistogram< STDTYPE >::getSum | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
getSum - return the current sum for all values in the window.
Returns NULL if the window is empty.
Definition at line 154 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::currentSum, WinAggHistogram< STDTYPE >::currentWindow, RegisterRef< TMPLT >::toNull(), and RegisterRef< TMPLT >::value().
Referenced by sum().
00155 { 00156 if (0 != currentWindow.size()) { 00157 node->value(currentSum); 00158 } else { 00159 node->toNull(); 00160 } 00161 }
void WinAggHistogram< STDTYPE >::getCount | ( | RegisterRef< int64_t > * | node | ) | [inline] |
getCount - returns the current number of entries in the window
Return is always int64_t
Definition at line 166 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::currentWindow, WinAggHistogram< STDTYPE >::nullRows, and RegisterRef< TMPLT >::value().
Referenced by count().
00167 { 00168 node->value(currentWindow.size() + nullRows); 00169 }
void WinAggHistogram< STDTYPE >::getAvg | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
getAvg - calculates and returns the average over the values currently in the tree.
Returns 0 if the window is empty.
Definition at line 175 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::currentSum, WinAggHistogram< STDTYPE >::currentWindow, and RegisterRef< TMPLT >::value().
Referenced by avg().
00176 { 00177 node->value( 00178 (0 != currentWindow.size()) ? 00179 (currentSum / static_cast<STDTYPE>(currentWindow.size())) : 00180 0); 00181 }
void WinAggHistogram< STDTYPE >::getFirstValue | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
getFirstValue - returns the first value which entered the tree
Returns NULL if the window is empty.
Definition at line 186 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::queue, RegisterRef< TMPLT >::toNull(), and RegisterRef< TMPLT >::value().
Referenced by firstValue().
00187 { 00188 if (queue.empty()) { 00189 node->toNull(); 00190 } else { 00191 node->value(queue.front()); 00192 } 00193 }
void WinAggHistogram< STDTYPE >::getLastValue | ( | RegisterRef< STDTYPE > * | node | ) | [inline] |
getLastValue - returns the last value which entered the tree
Returns NULL if the window is empty.
Definition at line 198 of file WinAggHistogram.h.
References WinAggHistogram< STDTYPE >::queue, RegisterRef< TMPLT >::toNull(), and RegisterRef< TMPLT >::value().
Referenced by lastValue().
00199 { 00200 if (queue.empty()) { 00201 node->toNull(); 00202 } else { 00203 node->value(queue.back()); 00204 } 00205 }
WinAggData WinAggHistogram< STDTYPE >::currentWindow [private] |
Definition at line 209 of file WinAggHistogram.h.
Referenced by WinAggHistogram< STDTYPE >::addRow(), WinAggHistogram< STDTYPE >::dropRow(), WinAggHistogram< STDTYPE >::getAvg(), WinAggHistogram< STDTYPE >::getCount(), WinAggHistogram< STDTYPE >::getMax(), WinAggHistogram< STDTYPE >::getMin(), and WinAggHistogram< STDTYPE >::getSum().
int64_t WinAggHistogram< STDTYPE >::nullRows [private] |
Definition at line 210 of file WinAggHistogram.h.
Referenced by WinAggHistogram< STDTYPE >::addRow(), WinAggHistogram< STDTYPE >::dropRow(), and WinAggHistogram< STDTYPE >::getCount().
STDTYPE WinAggHistogram< STDTYPE >::currentSum [private] |
Holds the running sum over the window.
Updated as entries are added/removed
Definition at line 220 of file WinAggHistogram.h.
Referenced by WinAggHistogram< STDTYPE >::addRow(), WinAggHistogram< STDTYPE >::dropRow(), WinAggHistogram< STDTYPE >::getAvg(), and WinAggHistogram< STDTYPE >::getSum().
WinAggQueue WinAggHistogram< STDTYPE >::queue [private] |
FIFO queue of values, to enable FIRST_VALUE/LAST_VALUE support.
Definition at line 223 of file WinAggHistogram.h.
Referenced by WinAggHistogram< STDTYPE >::addRow(), WinAggHistogram< STDTYPE >::dropRow(), WinAggHistogram< STDTYPE >::getFirstValue(), and WinAggHistogram< STDTYPE >::getLastValue().