#include <CircularBuffer.h>
Public Member Functions | |
CircularBuffer () | |
CircularBuffer (uint nEntriesInit) | |
void | clear () |
Initializes the buffer to an empty state. | |
void | resize (uint nEntriesInit) |
Resizes the number of entries in the circular buffer. | |
uint | size () |
| |
bool | empty () |
| |
bool | spaceAvailable () |
| |
uint | nFreeSpace () |
| |
uint | getFirstPos () |
| |
uint | getLastPos () |
| |
T & | reference_back () |
| |
void | push_back (T &newEntry) |
Adds an entry to the end of the buffer. | |
T & | reference_front () |
| |
void | pop_front () |
Removes the first entry from the buffer. | |
T & | operator[] (uint pos) |
Returns the entry at a specified position in the circular buffer. | |
bool | isReadOnly () |
| |
void | setReadOnly () |
Sets the buffer to a readonly state. | |
Private Member Functions | |
void | init (uint nEntriesInit) |
Initializes the buffer. | |
Private Attributes | |
std::vector< T > | buffer |
Vector used to represent the contents of the circular buffer. | |
uint | nEntries |
Number of entries in the buffer. | |
uint | nFreeEntries |
Number of free entries in the buffer. | |
uint | firstPos |
Position of the current, first entry in the circular buffer. | |
bool | readOnly |
If true, no additional new entries can be added to the buffer. |
The max size of the buffer must be set before the buffer can be used.
Definition at line 34 of file CircularBuffer.h.
CircularBuffer< T >::CircularBuffer | ( | ) | [inline, explicit] |
CircularBuffer< T >::CircularBuffer | ( | uint | nEntriesInit | ) | [inline, explicit] |
void CircularBuffer< T >::init | ( | uint | nEntriesInit | ) | [inline, private] |
Initializes the buffer.
nEntriesInit | size of the buffer |
Definition at line 68 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::CircularBuffer(), and CircularBuffer< std::pair< PageId, EntryT > >::resize().
void CircularBuffer< T >::clear | ( | ) | [inline] |
Initializes the buffer to an empty state.
Definition at line 89 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::init(), SegPageEntryIter< EntryT >::mapRange(), LcsRowScanExecStream::open(), and LbmGeneratorExecStream::open().
00090 { 00091 firstPos = 0; 00092 nFreeEntries = nEntries; 00093 readOnly = false; 00094 }
void CircularBuffer< T >::resize | ( | uint | nEntriesInit | ) | [inline] |
Resizes the number of entries in the circular buffer.
The buffer positions are also reset back to their initial state, so any existing entries stored in the buffer are ignored.
nEntriesInit | new number of entries |
Definition at line 103 of file CircularBuffer.h.
Referenced by LcsRowScanExecStream::LcsRowScanExecStream(), LbmGeneratorExecStream::prepare(), and SegPageEntryIter< EntryT >::resize().
00104 { 00105 init(nEntriesInit); 00106 }
uint CircularBuffer< T >::size | ( | ) | [inline] |
Definition at line 111 of file CircularBuffer.h.
Referenced by SegPageEntryIter< EntryT >::setPrefetchSource().
00112 { 00113 return nEntries; 00114 }
bool CircularBuffer< T >::empty | ( | ) | [inline] |
Definition at line 119 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::getFirstPos(), SegPageEntryIter< EntryT >::operator++(), CircularBuffer< std::pair< PageId, EntryT > >::pop_front(), SegPageEntryIter< EntryT >::prefetchPages(), CircularBuffer< std::pair< PageId, EntryT > >::reference_back(), and CircularBuffer< std::pair< PageId, EntryT > >::reference_front().
00120 { 00121 return (nFreeEntries == nEntries); 00122 }
bool CircularBuffer< T >::spaceAvailable | ( | ) | [inline] |
Definition at line 127 of file CircularBuffer.h.
Referenced by LcsRowScanExecStream::fillRidRunBuffer(), and SegPageEntryIter< EntryT >::prefetchPages().
00128 { 00129 return (nFreeEntries != 0); 00130 }
uint CircularBuffer< T >::nFreeSpace | ( | ) | [inline] |
Definition at line 135 of file CircularBuffer.h.
Referenced by LcsRowScanExecStream::execute().
00136 { 00137 return nFreeEntries; 00138 }
uint CircularBuffer< T >::getFirstPos | ( | ) | [inline] |
Definition at line 143 of file CircularBuffer.h.
uint CircularBuffer< T >::getLastPos | ( | ) | [inline] |
Definition at line 152 of file CircularBuffer.h.
Referenced by SegPageEntryIter< EntryT >::prefetchPages(), and CircularBuffer< std::pair< PageId, EntryT > >::reference_back().
00153 { 00154 return nEntries - nFreeEntries + firstPos - 1; 00155 }
T& CircularBuffer< T >::reference_back | ( | ) | [inline] |
Definition at line 160 of file CircularBuffer.h.
Referenced by SegPageEntryIter< EntryT >::prefetchPages().
00161 { 00162 assert(!empty()); 00163 uint lastEntry = getLastPos() % nEntries; 00164 return buffer[lastEntry]; 00165 }
void CircularBuffer< T >::push_back | ( | T & | newEntry | ) | [inline] |
Adds an entry to the end of the buffer.
Definition at line 170 of file CircularBuffer.h.
Referenced by LbmGeneratorExecStream::execute(), LcsRowScanExecStream::fillRidRunBuffer(), and SegPageEntryIter< EntryT >::prefetchPages().
00171 { 00172 assert(!readOnly); 00173 assert(nFreeEntries > 0); 00174 uint freeEntry = (nEntries - nFreeEntries + firstPos) % nEntries; 00175 buffer[freeEntry] = newEntry; 00176 nFreeEntries--; 00177 }
T& CircularBuffer< T >::reference_front | ( | ) | [inline] |
Definition at line 182 of file CircularBuffer.h.
Referenced by SegPageEntryIter< LcsRid >::operator *(), and SegPageEntryIter< EntryT >::operator++().
void CircularBuffer< T >::pop_front | ( | ) | [inline] |
Removes the first entry from the buffer.
Definition at line 191 of file CircularBuffer.h.
Referenced by SegPageEntryIter< EntryT >::operator++().
00192 { 00193 assert(!empty()); 00194 firstPos++; 00195 nFreeEntries++; 00196 }
T& CircularBuffer< T >::operator[] | ( | uint | pos | ) | [inline] |
Returns the entry at a specified position in the circular buffer.
pos | the position |
Definition at line 205 of file CircularBuffer.h.
bool CircularBuffer< T >::isReadOnly | ( | ) | [inline] |
Definition at line 213 of file CircularBuffer.h.
00214 { 00215 return readOnly; 00216 }
void CircularBuffer< T >::setReadOnly | ( | ) | [inline] |
Sets the buffer to a readonly state.
Definition at line 221 of file CircularBuffer.h.
Referenced by LcsRowScanExecStream::fillRidRunBuffer().
00222 { 00223 readOnly = true; 00224 }
std::vector<T> CircularBuffer< T >::buffer [private] |
Vector used to represent the contents of the circular buffer.
Definition at line 39 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::init(), CircularBuffer< std::pair< PageId, EntryT > >::operator[](), CircularBuffer< std::pair< PageId, EntryT > >::push_back(), CircularBuffer< std::pair< PageId, EntryT > >::reference_back(), and CircularBuffer< std::pair< PageId, EntryT > >::reference_front().
uint CircularBuffer< T >::nEntries [private] |
Number of entries in the buffer.
Definition at line 44 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::clear(), CircularBuffer< std::pair< PageId, EntryT > >::empty(), CircularBuffer< std::pair< PageId, EntryT > >::getLastPos(), CircularBuffer< std::pair< PageId, EntryT > >::init(), CircularBuffer< std::pair< PageId, EntryT > >::operator[](), CircularBuffer< std::pair< PageId, EntryT > >::push_back(), CircularBuffer< std::pair< PageId, EntryT > >::reference_back(), CircularBuffer< std::pair< PageId, EntryT > >::reference_front(), and CircularBuffer< std::pair< PageId, EntryT > >::size().
uint CircularBuffer< T >::nFreeEntries [private] |
Number of free entries in the buffer.
Definition at line 49 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::clear(), CircularBuffer< std::pair< PageId, EntryT > >::empty(), CircularBuffer< std::pair< PageId, EntryT > >::getLastPos(), CircularBuffer< std::pair< PageId, EntryT > >::nFreeSpace(), CircularBuffer< std::pair< PageId, EntryT > >::pop_front(), CircularBuffer< std::pair< PageId, EntryT > >::push_back(), and CircularBuffer< std::pair< PageId, EntryT > >::spaceAvailable().
uint CircularBuffer< T >::firstPos [private] |
Position of the current, first entry in the circular buffer.
Position always increases, even after positions in the circular buffer are recycled.
Definition at line 56 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::clear(), CircularBuffer< std::pair< PageId, EntryT > >::getFirstPos(), CircularBuffer< std::pair< PageId, EntryT > >::getLastPos(), CircularBuffer< std::pair< PageId, EntryT > >::pop_front(), CircularBuffer< std::pair< PageId, EntryT > >::push_back(), and CircularBuffer< std::pair< PageId, EntryT > >::reference_front().
bool CircularBuffer< T >::readOnly [private] |
If true, no additional new entries can be added to the buffer.
Definition at line 61 of file CircularBuffer.h.
Referenced by CircularBuffer< std::pair< PageId, EntryT > >::clear(), CircularBuffer< std::pair< PageId, EntryT > >::isReadOnly(), CircularBuffer< std::pair< PageId, EntryT > >::push_back(), and CircularBuffer< std::pair< PageId, EntryT > >::setReadOnly().