Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
abacus::AbaRing< Type > Class Template Reference

Bounded circular lists. More...

#include <ogdf/lib/abacus/ring.h>

+ Inheritance diagram for abacus::AbaRing< Type >:

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 charonOff (bool value)
 Converts a boolean variable to the strings "on" and "off".
 

Detailed Description

template<class Type>
class abacus::AbaRing< Type >

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.

Definition at line 51 of file ring.h.

Constructor & Destructor Documentation

◆ AbaRing()

template<class Type >
abacus::AbaRing< Type >::AbaRing ( int  size)
explicit

The constructor.

Parameters
sizeThe length of the ring.

◆ ~AbaRing()

template<class Type >
virtual abacus::AbaRing< Type >::~AbaRing ( )
inlinevirtual

The destructor.

Definition at line 61 of file ring.h.

Member Function Documentation

◆ clear()

template<class Type >
void abacus::AbaRing< Type >::clear ( )

Empties the ring.

◆ empty()

template<class Type >
bool abacus::AbaRing< Type >::empty ( ) const

Returns true if no element is contained in the ring, false otherwise.

◆ filled()

template<class Type >
bool abacus::AbaRing< Type >::filled ( ) const

Returns true If the ring is completely filled up, false otherwise.

◆ insert()

template<class Type >
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.

Parameters
elemThe element being inserted.

◆ newest()

template<class Type >
Type abacus::AbaRing< Type >::newest ( ) const

Returns the newest element in the ring.

The result is undefined if the ring is empty.

◆ newestIndex()

template<class Type >
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.

◆ number()

template<class Type >
int abacus::AbaRing< Type >::number ( ) const

Returns the current number of elements in the ring.

◆ oldest()

template<class Type >
Type abacus::AbaRing< Type >::oldest ( ) const

Returns the oldest element in the ring.

The result is undefined, if the ring is empty.

◆ oldestIndex()

template<class Type >
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.

◆ operator[]() [1/2]

template<class Type >
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.

Parameters
iThe element being accessed.

◆ operator[]() [2/2]

template<class Type >
const Type & abacus::AbaRing< Type >::operator[] ( int  i) const

The operator [] is overloaded for constant use.

◆ previous()

template<class Type >
int abacus::AbaRing< Type >::previous ( int  i,
Type &  p 
) const

Can be used to access any element between the oldest and newest inserted element.

Parameters
iThe element i elements before the newest element is retrieved. If i is 0, then the function retrieves the newest element.
pContains the i-th element before the newest one in a successful call.
Returns
0 If there are enough elements in the ring such that the element i entries before the newest one could be accessed,
1 otherwise.

◆ realloc()

template<class Type >
void abacus::AbaRing< Type >::realloc ( int  newSize)

Changes the length of the ring.

Parameters
newSizeThe 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.

◆ size()

template<class Type >
int abacus::AbaRing< Type >::size ( ) const

Returns the size of the ring.

Friends And Related Symbol Documentation

◆ operator<<

template<class Type >
std::ostream & operator<< ( std::ostream &  out,
const AbaRing< Type > &  ring 
)
friend

The output operator.

Writes the elements of the ring to an output stream starting with the oldest element in the ring.

Parameters
outThe output stream.
ringThe ring being output.
Returns
A reference to the output stream.

Member Data Documentation

◆ filled_

template<class Type >
bool abacus::AbaRing< Type >::filled_
private

This member becomes true if ring is completely filled up.

Definition at line 164 of file ring.h.

◆ head_

template<class Type >
int abacus::AbaRing< Type >::head_
private

The position in the array ring_ where the next element will be inserted.

Definition at line 161 of file ring.h.

◆ ring_

template<class Type >
Array<Type> abacus::AbaRing< Type >::ring_
private

An array storing the elements of the ring.

Definition at line 158 of file ring.h.


The documentation for this class was generated from the following file: