Bounded circular lists. More...
#include <ogdf/lib/abacus/ring.h>
Public Member Functions | |
AbaRing (int size) | |
The constructor. | |
virtual | ~AbaRing () |
The destructor. | |
void | clear () |
Empties the ring. | |
bool | empty () const |
Returns true if no element is contained in the ring, false otherwise. | |
bool | filled () const |
Returns true If the ring is completely filled up, false otherwise. | |
void | insert (Type elem) |
Inserts a new element into the ring. | |
Type | newest () const |
Returns the newest element in the ring. | |
int | newestIndex () const |
Returns the index of the newest element in the ring. | |
int | number () const |
Returns the current number of elements in the ring. | |
Type | oldest () const |
Returns the oldest element in the ring. | |
int | oldestIndex () const |
Returns the index of the oldest element in the ring. | |
Type & | operator[] (int i) |
Returns the i-th element of the ring. | |
const Type & | operator[] (int i) const |
The operator [] is overloaded for constant use. | |
int | previous (int i, Type &p) const |
Can be used to access any element between the oldest and newest inserted element. | |
void | realloc (int newSize) |
Changes the length of the ring. | |
int | size () const |
Returns the size of the ring. | |
Public Member Functions inherited from abacus::AbacusRoot | |
virtual | ~AbacusRoot () |
The destructor. | |
Private Attributes | |
bool | filled_ |
This member becomes true if ring is completely filled up. | |
int | head_ |
The position in the array ring_ where the next element will be inserted. | |
Array< Type > | ring_ |
An array storing the elements of the ring. | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const AbaRing< Type > &ring) |
The output operator. | |
Additional Inherited Members | |
Static Public Member Functions inherited from abacus::AbacusRoot | |
static bool | ascii2bool (const string &str) |
Converts the string str to a boolean value. | |
static bool | endsWith (const string &str, const string &end) |
Returns true if str ends with end, false otherwise. | |
static double | fracPart (double x) |
Returns the absolute value of the fractional part of x. | |
static const char * | onOff (bool value) |
Converts a boolean variable to the strings "on" and "off". | |
Bounded circular lists.
The template AbaRing implements a bounded circular list with the property that if the list is full and an element is inserted the oldest element of the ring is removed. With this implementation single elements cannot be removed, but the whole AbaRing can be cleared.
|
explicit |
The constructor.
size | The length of the ring. |
|
inlinevirtual |
void abacus::AbaRing< Type >::clear | ( | ) |
Empties the ring.
bool abacus::AbaRing< Type >::empty | ( | ) | const |
Returns true if no element is contained in the ring, false otherwise.
bool abacus::AbaRing< Type >::filled | ( | ) | const |
Returns true If the ring is completely filled up, false otherwise.
void abacus::AbaRing< Type >::insert | ( | Type | elem | ) |
Inserts a new element into the ring.
If the ring is already full, this operation overwrites the oldest element in the ring.
elem | The element being inserted. |
Type abacus::AbaRing< Type >::newest | ( | ) | const |
Returns the newest element in the ring.
The result is undefined if the ring is empty.
int abacus::AbaRing< Type >::newestIndex | ( | ) | const |
Returns the index of the newest element in the ring.
The result is undefined if the ring is empty.
int abacus::AbaRing< Type >::number | ( | ) | const |
Returns the current number of elements in the ring.
Type abacus::AbaRing< Type >::oldest | ( | ) | const |
Returns the oldest element in the ring.
The result is undefined, if the ring is empty.
int abacus::AbaRing< Type >::oldestIndex | ( | ) | const |
Returns the index of the oldest element in the ring.
The result is undefined, if the ring is empty.
Type & abacus::AbaRing< Type >::operator[] | ( | int | i | ) |
Returns the i-th element of the ring.
The operation is undefined if no element has been inserted in the i-th position so far.
i | The element being accessed. |
const Type & abacus::AbaRing< Type >::operator[] | ( | int | i | ) | const |
The operator [] is overloaded for constant use.
int abacus::AbaRing< Type >::previous | ( | int | i, |
Type & | p | ||
) | const |
Can be used to access any element between the oldest and newest inserted element.
i | The element i elements before the newest element is retrieved. If i is 0, then the function retrieves the newest element. |
p | Contains the i-th element before the newest one in a successful call. |
void abacus::AbaRing< Type >::realloc | ( | int | newSize | ) |
Changes the length of the ring.
newSize | The new length of the ring. If the ring decreases below the current number of elements in the ring, then the newSize newest elements stay in the ring. |
int abacus::AbaRing< Type >::size | ( | ) | const |
Returns the size of the ring.
|
friend |
The output operator.
Writes the elements of the ring to an output stream starting with the oldest element in the ring.
out | The output stream. |
ring | The ring being output. |
|
private |
|
private |
|
private |