Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ogdf::SListPure< E > Class Template Reference

Singly linked lists. More...

#include <ogdf/basic/SList.h>

+ Inheritance diagram for ogdf::SListPure< E >:

Public Types

using const_iterator = SListConstIterator< E >
 Provides a forward iterator that can read a const element in a list.
 
using const_reference = const E &
 Provides a reference to a const element stored in a list for reading and performing const operations.
 
using iterator = SListIterator< E >
 Provides a forward iterator that can read or modify any element in a list.
 
using reference = E &
 Provides a reference to an element stored in a list.
 
using value_type = E
 Represents the data type stored in a list element.
 

Public Member Functions

 SListPure ()
 Constructs an empty singly linked list.
 
 SListPure (const SListPure< E > &L)
 Constructs a singly linked list that is a copy of L.
 
 SListPure (SListPure< E > &&L)
 Constructs a singly linked list containing the elements of L (move semantics).
 
 SListPure (std::initializer_list< E > init)
 Constructs a singly linked list containing the elements in init.
 
virtual ~SListPure ()
 Destructor.
 
Access methods

These methods provide simple access without changing the list.

bool empty () const
 Returns true iff the list is empty.
 
virtual int size () const
 Returns the number of elements in the list.
 
const_reference front () const
 Returns a reference to the first element.
 
reference front ()
 Returns a reference to the first element.
 
const_reference back () const
 Returns a reference to the last element.
 
reference back ()
 Returns a reference to the last element.
 
const_iterator get (int pos) const
 Returns an iterator pointing to the element at position pos.
 
iterator get (int pos)
 Returns an iterator pointing to the element at position pos.
 
int pos (const_iterator it) const
 Returns the position (starting with 0) of it in the list.
 
Iterators

These methods return forward iterators to elements in the list and allow to iterate over the elements in linear or cyclic order.

iterator begin ()
 Returns an iterator to the first element of the list.
 
const_iterator begin () const
 Returns a const iterator to the first element of the list.
 
const_iterator cbegin () const
 Returns a const iterator to the first element of the list.
 
iterator end ()
 Returns an iterator to one-past-last element of the list.
 
const_iterator end () const
 Returns a const iterator to one-past-last element of the list.
 
const_iterator cend () const
 Returns a const iterator to one-past-last element of the list.
 
iterator backIterator ()
 Returns an iterator to the last element of the list.
 
const_iterator backIterator () const
 Returns a const iterator to the last element of the list.
 
const_iterator cyclicSucc (const_iterator it) const
 Returns an iterator to the cyclic successor of it.
 
iterator cyclicSucc (iterator it)
 Returns an iterator to the cyclic successor of it.
 
Operators

The following operators are provided by lists.

SListPure< E > & operator= (const SListPure< E > &L)
 Assignment operator.
 
SListPure< E > & operator= (SListPure< E > &&L)
 Assignment operator (move semantics).
 
bool operator== (const SListPure< E > &L) const
 Equality operator.
 
bool operator!= (const SListPure< E > &L) const
 Inequality operator.
 
Adding elements

These method add elements to the list.

iterator pushFront (const E &x)
 Adds element x at the beginning of the list.
 
template<class... Args>
iterator emplaceFront (Args &&... args)
 Adds a new element at the beginning of the list.
 
iterator pushBack (const E &x)
 Adds element x at the end of the list.
 
template<class... Args>
iterator emplaceBack (Args &&... args)
 Adds a new element at the end of the list.
 
iterator insertAfter (const E &x, iterator itBefore)
 Inserts element x after itBefore.
 
Removing elements

These method remove elements from the list.

void popFront ()
 Removes the first element from the list.
 
popFrontRet ()
 Removes the first element from the list and returns it.
 
void delSucc (iterator itBefore)
 Removes the succesor of itBefore.
 
void clear ()
 Removes all elements from the list.
 
Moving elements

The method allow to change the order of elements within the list, or to move elements to another list.

void moveFrontToFront (SListPure< E > &L2)
 Moves the first element of this list to the begin of list L2.
 
void moveFrontToBack (SListPure< E > &L2)
 Moves the first element of this list to the end of list L2.
 
void moveFrontToSucc (SListPure< E > &L2, iterator itBefore)
 Moves the first element of this list to list L2 inserted after itBefore.
 
void conc (SListPure< E > &L2)
 Appends L2 to this list and makes L2 empty.
 
void reverse ()
 Reverses the order of the list elements.
 
Searching and sorting

These methods provide searching for values and sorting the list.

SListConstIterator< E > search (const E &e) const
 Scans the list for the specified element and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.
 
SListIterator< E > search (const E &e)
 Scans the list for the specified element and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.
 
template<class COMPARER >
SListConstIterator< E > search (const E &e, const COMPARER &comp) const
 Scans the list for the specified element (using the user-defined comparer) and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.
 
template<class COMPARER >
SListIterator< E > search (const E &e, const COMPARER &comp)
 Scans the list for the specified element (using the user-defined comparer) and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.
 
void quicksort ()
 Sorts the list using Quicksort.
 
template<class COMPARER >
void quicksort (const COMPARER &comp)
 Sorts the list using Quicksort and comparer comp.
 
void bucketSort (int l, int h, BucketFunc< E > &f)
 Sorts the list using bucket sort.
 
void bucketSort (BucketFunc< E > &f)
 Sorts the list using bucket sort.
 
Random elements and permutations

These methods allow to select a random element in the list, or to randomly permute the list.

const_iterator chooseIterator (std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
 Returns an iterator to a random element.
 
iterator chooseIterator (std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
 Returns an iterator to a random element.
 
const_reference chooseElement (std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true) const
 Returns a random element.
 
reference chooseElement (std::function< bool(const E &)> includeElement=[](const E &) { return true;}, bool isFastTest=true)
 Returns a random element.
 
void permute ()
 Randomly permutes the elements in the list.
 
template<class RNG >
void permute (RNG &rng)
 Randomly permutes the elements in the list using random number generator rng.
 

Protected Member Functions

void copy (const SListPure< E > &L)
 
template<class RNG >
void permute (const int n, RNG &rng)
 Permutes elements in list randomly; n is the length of the list.
 
void reassignListRefs (SListElement< E > *start=nullptr)
 Sets the debug reference of all list elements starting at start to this.
 

Private Attributes

SListElement< E > * m_head
 Pointer to first element.
 
SListElement< E > * m_tail
 Pointer to last element.
 

Detailed Description

template<class E>
class ogdf::SListPure< E >

Singly linked lists.

Use ogdf::SListConstIterator or ogdf::SListIterator in order to iterate over the list.

In contrast to ogdf::SList, instances of ogdf::SListPure do not store the length of the list.

Template Parameters
Eis the data type stored in list elements.

Definition at line 179 of file SList.h.

Member Typedef Documentation

◆ const_iterator

template<class E >
using ogdf::SListPure< E >::const_iterator = SListConstIterator<E>

Provides a forward iterator that can read a const element in a list.

Definition at line 191 of file SList.h.

◆ const_reference

template<class E >
using ogdf::SListPure< E >::const_reference = const E&

Provides a reference to a const element stored in a list for reading and performing const operations.

Definition at line 189 of file SList.h.

◆ iterator

template<class E >
using ogdf::SListPure< E >::iterator = SListIterator<E>

Provides a forward iterator that can read or modify any element in a list.

Definition at line 193 of file SList.h.

◆ reference

template<class E >
using ogdf::SListPure< E >::reference = E&

Provides a reference to an element stored in a list.

Definition at line 187 of file SList.h.

◆ value_type

template<class E >
using ogdf::SListPure< E >::value_type = E

Represents the data type stored in a list element.

Definition at line 185 of file SList.h.

Constructor & Destructor Documentation

◆ SListPure() [1/4]

template<class E >
ogdf::SListPure< E >::SListPure ( )
inline

Constructs an empty singly linked list.

Definition at line 196 of file SList.h.

◆ SListPure() [2/4]

template<class E >
ogdf::SListPure< E >::SListPure ( std::initializer_list< E >  init)
inline

Constructs a singly linked list containing the elements in init.

Definition at line 199 of file SList.h.

◆ SListPure() [3/4]

template<class E >
ogdf::SListPure< E >::SListPure ( const SListPure< E > &  L)
inline

Constructs a singly linked list that is a copy of L.

Definition at line 206 of file SList.h.

◆ SListPure() [4/4]

template<class E >
ogdf::SListPure< E >::SListPure ( SListPure< E > &&  L)
inline

Constructs a singly linked list containing the elements of L (move semantics).

The list L is empty afterwards.

Definition at line 212 of file SList.h.

◆ ~SListPure()

template<class E >
virtual ogdf::SListPure< E >::~SListPure ( )
inlinevirtual

Destructor.

Definition at line 217 of file SList.h.

Member Function Documentation

◆ back() [1/2]

template<class E >
reference ogdf::SListPure< E >::back ( )
inline

Returns a reference to the last element.

Precondition
The list is not empty!

Definition at line 272 of file SList.h.

◆ back() [2/2]

template<class E >
const_reference ogdf::SListPure< E >::back ( ) const
inline

Returns a reference to the last element.

Precondition
The list is not empty!

Definition at line 263 of file SList.h.

◆ backIterator() [1/2]

template<class E >
iterator ogdf::SListPure< E >::backIterator ( )
inline

Returns an iterator to the last element of the list.

If the list is empty, an invalid iterator is returned.

Definition at line 368 of file SList.h.

◆ backIterator() [2/2]

template<class E >
const_iterator ogdf::SListPure< E >::backIterator ( ) const
inline

Returns a const iterator to the last element of the list.

If the list is empty, an invalid iterator is returned.

Definition at line 374 of file SList.h.

◆ begin() [1/2]

template<class E >
iterator ogdf::SListPure< E >::begin ( )
inline

Returns an iterator to the first element of the list.

If the list is empty, a null pointer iterator is returned.

Definition at line 332 of file SList.h.

◆ begin() [2/2]

template<class E >
const_iterator ogdf::SListPure< E >::begin ( ) const
inline

Returns a const iterator to the first element of the list.

If the list is empty, a null pointer iterator is returned.

Definition at line 338 of file SList.h.

◆ bucketSort() [1/2]

template<class E >
void ogdf::SListPure< E >::bucketSort ( BucketFunc< E > &  f)

Sorts the list using bucket sort.

Definition at line 1035 of file SList.h.

◆ bucketSort() [2/2]

template<class E >
void ogdf::SListPure< E >::bucketSort ( int  l,
int  h,
BucketFunc< E > &  f 
)

Sorts the list using bucket sort.

Parameters
lis the lowest bucket that will occur.
his the highest bucket that will occur.
freturns the bucket for each element.
Precondition
The bucket function f will only return bucket values between l and h for this list.

Definition at line 1059 of file SList.h.

◆ cbegin()

template<class E >
const_iterator ogdf::SListPure< E >::cbegin ( ) const
inline

Returns a const iterator to the first element of the list.

If the list is empty, a null pointer iterator is returned.

Definition at line 344 of file SList.h.

◆ cend()

template<class E >
const_iterator ogdf::SListPure< E >::cend ( ) const
inline

Returns a const iterator to one-past-last element of the list.

This is always a null pointer iterator.

Definition at line 362 of file SList.h.

◆ chooseElement() [1/2]

template<class E >
reference ogdf::SListPure< E >::chooseElement ( std::function< bool(const E &)>  includeElement = [](const E&) { return true; },
bool  isFastTest = true 
)
inline

Returns a random element.

Takes linear time.

Precondition
Requires at least one feasible element to exist.
See also
chooseIteratorFrom

Definition at line 776 of file SList.h.

◆ chooseElement() [2/2]

template<class E >
const_reference ogdf::SListPure< E >::chooseElement ( std::function< bool(const E &)>  includeElement = [](const E&) { return true; },
bool  isFastTest = true 
) const
inline

Returns a random element.

Takes linear time.

Precondition
Requires at least one feasible element to exist.
See also
chooseIteratorFrom

Definition at line 767 of file SList.h.

◆ chooseIterator() [1/2]

template<class E >
iterator ogdf::SListPure< E >::chooseIterator ( std::function< bool(const E &)>  includeElement = [](const E&) { return true; },
bool  isFastTest = true 
)
inline

Returns an iterator to a random element.

Takes linear time. An invalid iterator is returned iff no feasible element exists.

See also
chooseIteratorFrom

Definition at line 760 of file SList.h.

◆ chooseIterator() [2/2]

template<class E >
const_iterator ogdf::SListPure< E >::chooseIterator ( std::function< bool(const E &)>  includeElement = [](const E&) { return true; },
bool  isFastTest = true 
) const
inline

Returns an iterator to a random element.

Takes linear time. An invalid iterator is returned iff no feasible element exists.

See also
chooseIteratorFrom

Definition at line 753 of file SList.h.

◆ clear()

template<class E >
void ogdf::SListPure< E >::clear ( )
inline

Removes all elements from the list.

Definition at line 555 of file SList.h.

◆ conc()

template<class E >
void ogdf::SListPure< E >::conc ( SListPure< E > &  L2)
inline

Appends L2 to this list and makes L2 empty.

Definition at line 638 of file SList.h.

◆ copy()

template<class E >
void ogdf::SListPure< E >::copy ( const SListPure< E > &  L)
inlineprotected

Definition at line 799 of file SList.h.

◆ cyclicSucc() [1/2]

template<class E >
const_iterator ogdf::SListPure< E >::cyclicSucc ( const_iterator  it) const
inline

Returns an iterator to the cyclic successor of it.

Precondition
it points to an element in this list!

Definition at line 380 of file SList.h.

◆ cyclicSucc() [2/2]

template<class E >
iterator ogdf::SListPure< E >::cyclicSucc ( iterator  it)
inline

Returns an iterator to the cyclic successor of it.

Precondition
it points to an element in this list!

Definition at line 390 of file SList.h.

◆ delSucc()

template<class E >
void ogdf::SListPure< E >::delSucc ( iterator  itBefore)
inline

Removes the succesor of itBefore.

Precondition
itBefore points to an element in this list.

Definition at line 542 of file SList.h.

◆ emplaceBack()

template<class E >
template<class... Args>
iterator ogdf::SListPure< E >::emplaceBack ( Args &&...  args)
inline

Adds a new element at the end of the list.

The element is constructed in-place with exactly the same arguments args as supplied to the function.

Definition at line 484 of file SList.h.

◆ emplaceFront()

template<class E >
template<class... Args>
iterator ogdf::SListPure< E >::emplaceFront ( Args &&...  args)
inline

Adds a new element at the beginning of the list.

The element is constructed in-place with exactly the same arguments args as supplied to the function.

Definition at line 460 of file SList.h.

◆ empty()

template<class E >
bool ogdf::SListPure< E >::empty ( ) const
inline

Returns true iff the list is empty.

Definition at line 226 of file SList.h.

◆ end() [1/2]

template<class E >
iterator ogdf::SListPure< E >::end ( )
inline

Returns an iterator to one-past-last element of the list.

This is always a null pointer iterator.

Definition at line 350 of file SList.h.

◆ end() [2/2]

template<class E >
const_iterator ogdf::SListPure< E >::end ( ) const
inline

Returns a const iterator to one-past-last element of the list.

This is always a null pointer iterator.

Definition at line 356 of file SList.h.

◆ front() [1/2]

template<class E >
reference ogdf::SListPure< E >::front ( )
inline

Returns a reference to the first element.

Precondition
The list is not empty!

Definition at line 254 of file SList.h.

◆ front() [2/2]

template<class E >
const_reference ogdf::SListPure< E >::front ( ) const
inline

Returns a reference to the first element.

Precondition
The list is not empty!

Definition at line 245 of file SList.h.

◆ get() [1/2]

template<class E >
iterator ogdf::SListPure< E >::get ( int  pos)
inline

Returns an iterator pointing to the element at position pos.

The running time of this method is linear in pos.

Definition at line 295 of file SList.h.

◆ get() [2/2]

template<class E >
const_iterator ogdf::SListPure< E >::get ( int  pos) const
inline

Returns an iterator pointing to the element at position pos.

The running time of this method is linear in pos.

Definition at line 281 of file SList.h.

◆ insertAfter()

template<class E >
iterator ogdf::SListPure< E >::insertAfter ( const E &  x,
iterator  itBefore 
)
inline

Inserts element x after itBefore.

Precondition
itBefore references an element in this list.

Definition at line 498 of file SList.h.

◆ moveFrontToBack()

template<class E >
void ogdf::SListPure< E >::moveFrontToBack ( SListPure< E > &  L2)
inline

Moves the first element of this list to the end of list L2.

Definition at line 596 of file SList.h.

◆ moveFrontToFront()

template<class E >
void ogdf::SListPure< E >::moveFrontToFront ( SListPure< E > &  L2)
inline

Moves the first element of this list to the begin of list L2.

Definition at line 578 of file SList.h.

◆ moveFrontToSucc()

template<class E >
void ogdf::SListPure< E >::moveFrontToSucc ( SListPure< E > &  L2,
iterator  itBefore 
)
inline

Moves the first element of this list to list L2 inserted after itBefore.

Precondition
itBefore points to an element in L2.

Definition at line 618 of file SList.h.

◆ operator!=()

template<class E >
bool ogdf::SListPure< E >::operator!= ( const SListPure< E > &  L) const
inline

Inequality operator.

Definition at line 437 of file SList.h.

◆ operator=() [1/2]

template<class E >
SListPure< E > & ogdf::SListPure< E >::operator= ( const SListPure< E > &  L)
inline

Assignment operator.

Definition at line 404 of file SList.h.

◆ operator=() [2/2]

template<class E >
SListPure< E > & ogdf::SListPure< E >::operator= ( SListPure< E > &&  L)
inline

Assignment operator (move semantics).

The list L is empty afterwards.

Definition at line 414 of file SList.h.

◆ operator==()

template<class E >
bool ogdf::SListPure< E >::operator== ( const SListPure< E > &  L) const
inline

Equality operator.

Definition at line 424 of file SList.h.

◆ permute() [1/3]

template<class E >
void ogdf::SListPure< E >::permute ( )
inline

Randomly permutes the elements in the list.

Definition at line 785 of file SList.h.

◆ permute() [2/3]

template<class E >
template<class RNG >
void ogdf::SListPure< E >::permute ( const int  n,
RNG rng 
)
protected

Permutes elements in list randomly; n is the length of the list.

Definition at line 1096 of file SList.h.

◆ permute() [3/3]

template<class E >
template<class RNG >
void ogdf::SListPure< E >::permute ( RNG rng)
inline

Randomly permutes the elements in the list using random number generator rng.

Definition at line 792 of file SList.h.

◆ popFront()

template<class E >
void ogdf::SListPure< E >::popFront ( )
inline

Removes the first element from the list.

Precondition
The list is not empty!

Definition at line 519 of file SList.h.

◆ popFrontRet()

template<class E >
E ogdf::SListPure< E >::popFrontRet ( )
inline

Removes the first element from the list and returns it.

Precondition
The list is not empty!

Definition at line 532 of file SList.h.

◆ pos()

template<class E >
int ogdf::SListPure< E >::pos ( const_iterator  it) const
inline

Returns the position (starting with 0) of it in the list.

Positions are numbered 0,1,...

Precondition
it is an iterator pointing to an element in this list.

Definition at line 310 of file SList.h.

◆ pushBack()

template<class E >
iterator ogdf::SListPure< E >::pushBack ( const E &  x)
inline

Adds element x at the end of the list.

Definition at line 469 of file SList.h.

◆ pushFront()

template<class E >
iterator ogdf::SListPure< E >::pushFront ( const E &  x)
inline

Adds element x at the beginning of the list.

Definition at line 447 of file SList.h.

◆ quicksort() [1/2]

template<class E >
void ogdf::SListPure< E >::quicksort ( )
inline

Sorts the list using Quicksort.

Definition at line 724 of file SList.h.

◆ quicksort() [2/2]

template<class E >
template<class COMPARER >
void ogdf::SListPure< E >::quicksort ( const COMPARER comp)
inline

Sorts the list using Quicksort and comparer comp.

Definition at line 728 of file SList.h.

◆ reassignListRefs()

template<class E >
void ogdf::SListPure< E >::reassignListRefs ( SListElement< E > *  start = nullptr)
inlineprotected

Sets the debug reference of all list elements starting at start to this.

Definition at line 810 of file SList.h.

◆ reverse()

template<class E >
void ogdf::SListPure< E >::reverse ( )
inline

Reverses the order of the list elements.

Definition at line 654 of file SList.h.

◆ search() [1/4]

template<class E >
SListIterator< E > ogdf::SListPure< E >::search ( const E &  e)
inline

Scans the list for the specified element and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.

Definition at line 685 of file SList.h.

◆ search() [2/4]

template<class E >
SListConstIterator< E > ogdf::SListPure< E >::search ( const E &  e) const
inline

Scans the list for the specified element and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.

Definition at line 673 of file SList.h.

◆ search() [3/4]

template<class E >
template<class COMPARER >
SListIterator< E > ogdf::SListPure< E >::search ( const E &  e,
const COMPARER comp 
)
inline

Scans the list for the specified element (using the user-defined comparer) and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.

Definition at line 713 of file SList.h.

◆ search() [4/4]

template<class E >
template<class COMPARER >
SListConstIterator< E > ogdf::SListPure< E >::search ( const E &  e,
const COMPARER comp 
) const
inline

Scans the list for the specified element (using the user-defined comparer) and returns an iterator to the first occurrence in the list, or an invalid iterator if not found.

Definition at line 699 of file SList.h.

◆ size()

template<class E >
virtual int ogdf::SListPure< E >::size ( ) const
inlinevirtual

Returns the number of elements in the list.

Notice that this method requires to iterate over the whole list and takes linear running time! If you require frequent access to the size of the list, consider using SList instead of SListPure.

Reimplemented in ogdf::Queue< E >, ogdf::SList< E >, ogdf::SList< double >, ogdf::SList< int >, ogdf::SList< ogdf::AdjElement >, ogdf::SList< ogdf::EdgeElement >, ogdf::SList< ogdf::MultiEdgeApproxInserter::VertexBlock >, ogdf::SList< ogdf::NodeElement >, and ogdf::SList< ogdf::SimpleCluster * >.

Definition at line 233 of file SList.h.

Member Data Documentation

◆ m_head

template<class E >
SListElement<E>* ogdf::SListPure< E >::m_head
private

Pointer to first element.

Definition at line 180 of file SList.h.

◆ m_tail

template<class E >
SListElement<E>* ogdf::SListPure< E >::m_tail
private

Pointer to last element.

Definition at line 181 of file SList.h.


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