Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

abacus::AbaRing< Type > Class Template Reference

Bounded circular lists. More...

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

Public Member Functions

 AbaRing (int size)
 The constructor. More...
 
virtual ~AbaRing ()
 The destructor. More...
 
void clear ()
 Empties the ring. More...
 
bool empty () const
 Returns true if no element is contained in the ring, false otherwise. More...
 
bool filled () const
 Returns true If the ring is completely filled up, false otherwise. More...
 
void insert (Type elem)
 Inserts a new element into the ring. More...
 
Type newest () const
 Returns the newest element in the ring. More...
 
int newestIndex () const
 Returns the index of the newest element in the ring. More...
 
int number () const
 Returns the current number of elements in the ring. More...
 
Type oldest () const
 Returns the oldest element in the ring. More...
 
int oldestIndex () const
 Returns the index of the oldest element in the ring. More...
 
Type & operator[] (int i)
 Returns the i-th element of the ring. More...
 
const Type & operator[] (int i) const
 The operator [] is overloaded for constant use. More...
 
int previous (int i, Type &p) const
 Can be used to access any element between the oldest and newest inserted element. More...
 
void realloc (int newSize)
 Changes the length of the ring. More...
 
int size () const
 Returns the size of the ring. More...
 

Private Attributes

bool filled_
 This member becomes true if ring is completely filled up. More...
 
int head_
 The position in the array ring_ where the next element will be inserted. More...
 
Array< Type > ring_
 An array storing the elements of the ring. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const AbaRing< Type > &ring)
 The output operator. More...
 

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 38 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 Function 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: