Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
List< T, E, A > Class Template Reference

#include <elm/data/List.h>

+ Inheritance diagram for List< T, E, A >:

Classes

class  Iter
 
class  PrecIter
 
class  SubIter
 

Public Member Functions

 List ()
 
 List (const List< T, E, A > &list)
 
 ~List (void)
 
E & equivalence ()
 
const E & equivalence () const
 
A & allocator ()
 
void copy (const List< T, E, A > &list)
 
Iter items (void) const
 
Iter operator* (void) const
 
 operator Iter (void) const
 
Iter begin (void) const
 
Iter end (void) const
 
int count (void) const
 
bool contains (const T &item) const
 
bool isEmpty (void) const
 
 operator bool (void) const
 
bool equals (const List< T > &l) const
 
const T & at (const Iter &i) const
 
void clear (void)
 
void add (const T &value)
 
template<class C >
void addAll (const C &items)
 
template<class C >
void removeAll (const C &items)
 
void remove (const T &value)
 
T & at (const Iter &i)
 
void remove (PrecIter &iter)
 
T & first (void)
 
const T & first (void) const
 
T & last (void)
 
const T & last (void) const
 
T & nth (int n)
 
const T & nth (int n) const
 
Iter find (const T &item) const
 
Iter find (const T &item, const Iter &pos) const
 
void addFirst (const T &value)
 
void addLast (const T &value)
 
void addAfter (const Iter &pos, const T &value)
 
void addBefore (PrecIter &pos, const T &value)
 
void removeFirst (void)
 
void removeLast (void)
 
void set (const Iter &pos, const T &item)
 
const T & top (void) const
 
pop (void)
 
void push (const T &i)
 
void reset (void)
 
Listoperator= (const List &list)
 
bool operator& (const T &e) const
 
T & operator[] (int k)
 
const T & operator[] (int k) const
 
bool operator== (const List< T > &l) const
 
bool operator!= (const List< T > &l) const
 
List< T > & operator+= (const T &h)
 
List< T > & operator+= (const List< T > &l)
 
List< T > & operator-= (const T &h)
 
List< T > & operator-= (const List< T > &l)
 
- Public Member Functions inherited from Equiv< T >
bool isEqual (const T &v1, const T &v2) const
 
- Public Member Functions inherited from DefaultAllocatorDelegate
t::ptr allocate (t::size size) const
 
void free (t::ptr p) const
 
template<class T >
T * alloc () const
 

Static Public Attributes

static List< T, E, A > null
 
- Static Public Attributes inherited from Equiv< T >
static Equiv< T > def
 

Additional Inherited Members

- Public Types inherited from Equiv< T >
typedef T t
 
- Static Public Member Functions inherited from Equiv< T >
static bool equals (const T &v1, const T &v2)
 

Detailed Description

template<class T, class E = Equiv<T>, class A = DefaultAlloc>
class elm::List< T, E, A >

This class provides a generic implementation of single-link lists.

Performances
  • addition – O(1)
  • removal – O(n)
  • find – O(n)
  • memory – 2 pointers + 1 pointer / element
Implemented concepts:
Parameters
TType of data stored in the list.
MManager supporting equivallence and allocation.

Constructor & Destructor Documentation

◆ List() [1/2]

List ( )
inline

◆ List() [2/2]

List ( const List< T, E, A > &  list)
inline

◆ ~List()

~List ( void  )
inline

Member Function Documentation

◆ add()

void add ( const T &  value)
inline

Add an item to the list. In fact, alias for addFirst().

Parameters
valueValue to add.

References List< T, E, A >::addFirst().

Referenced by CleanList::add(), List< T, E, A >::addAll(), HashSet< T, H, A >::meet(), and List< T, E, A >::operator+=().

◆ addAfter()

void addAfter ( const Iter pos,
const T &  value 
)
inline

Add an item after the one pointed by pos.

Parameters
posIterator pointing the element to add after.
valueValue to add.
Warning
pos must not point at the end of the list!

◆ addAll()

void addAll ( const C &  items)
inline

◆ addBefore()

void addBefore ( PrecIter pos,
const T &  value 
)
inline

Add item before the element pointer by pos.

Parameters
posIterator pointing the element to add before.
valueValue to add.
Warning
pos must not point at the end of the list!

References List< T, E, A >::addFirst().

Referenced by SortedList< T, C, A >::add(), and ListSet< T, C, A >::join().

◆ addFirst()

void addFirst ( const T &  item)
inline

Add the given item at the first position in the list.

Parameters
itemItem to add.

References SLList::addFirst().

Referenced by List< T, E, A >::add(), List< T, E, A >::addBefore(), List< T, E, A >::copy(), and List< T, E, A >::push().

◆ addLast()

void addLast ( const T &  item)
inline

Add the given item at the last position in the list. Remark that this method is really inefficient. Its working time is in O(n), n number of nodes in the list. Use it only with small list or revert to more powerful data structures.

Parameters
itemItem to add.

References SLList::addLast().

Referenced by SortedList< T, C, A >::add().

◆ allocator()

A& allocator ( )
inline

◆ at() [1/2]

T& at ( const Iter i)
inline

◆ at() [2/2]

const T& at ( const Iter i) const
inline

◆ begin()

Iter begin ( void  ) const
inline

◆ clear()

◆ contains()

bool contains ( const T &  item) const
inline

Test if an item is in the list.

Parameters
itemItem to look for.
Returns
True if the item is the list, false else.

References elm::iter().

Referenced by List< T, E, A >::operator&(), and SortedList< T, C, A >::operator&().

◆ copy()

void copy ( const List< T, E, A > &  list)
inline

Copy the given list in the current list (removing the previous items of the current list).

Parameters
listList to copy in.

References List< T, E, A >::addFirst(), List< T, E, A >::clear(), and elm::io::list().

Referenced by List< T, E, A >::List(), SortedList< T, C, A >::copy(), List< T, E, A >::operator=(), and SortedList< T, C, A >::operator=().

◆ count()

int count ( void  ) const
inline

Count the items in the list.

Returns
Item count.

References SLList::count().

Referenced by SortedList< T, C, A >::count().

◆ end()

List::iter end ( void  ) const
inline

Get an iterator on the end of the list.

Returns
Ending iterator.

◆ equals()

bool equals ( const List< T > &  l) const
inline

Test if both lists are equal.

Parameters
lList to compare with.
Returns
True if they are equal, false else.

Referenced by List< T, E, A >::operator!=(), and List< T, E, A >::operator==().

◆ equivalence() [1/2]

E& equivalence ( )
inline

◆ equivalence() [2/2]

const E& equivalence ( ) const
inline

◆ find() [1/2]

prec_iter find ( const T &  item) const
inline

Find an element in the list.

Parameters
itemElement to look for.
Returns
Iterator on the found element or iterator on the list end.

References List< T, E, A >::items().

◆ find() [2/2]

Iter find ( const T &  item,
const Iter pos 
) const
inline

◆ first() [1/2]

◆ first() [2/2]

const T & first ( void  ) const
inline

Get the first item of the list.

Returns
First item.
Warning
It is an error to call this method if the list is empty.

◆ isEmpty()

bool isEmpty ( void  ) const
inline

Test if the list is empty.

Returns
True if the list is empty, false else.

References SLList::isEmpty().

Referenced by SortedList< T, C, A >::isEmpty(), List< T, E, A >::operator bool(), SortedList< T, C, A >::operator bool(), and List< T, E, A >::remove().

◆ items()

◆ last() [1/2]

T& last ( void  )
inline

◆ last() [2/2]

const T & last ( void  ) const
inline

Get the last item of the list. Remark that this method is really inefficient. Its working time is in O(n), n number of nodes in the list. Use it only with small list or revert to more powerful data structures.

Returns
Last item.
Warning
It is an error to call this method if the list is empty.

◆ nth() [1/2]

T& nth ( int  n)
inline

◆ nth() [2/2]

const T& nth ( int  n) const
inline

◆ operator bool()

operator bool ( void  ) const
inline

◆ operator Iter()

operator Iter ( void  ) const
inline

◆ operator!=()

bool operator!= ( const List< T > &  l) const
inline

◆ operator&()

bool operator& ( const T &  e) const
inline

◆ operator*()

Iter operator* ( void  ) const
inline

◆ operator+=() [1/2]

List<T>& operator+= ( const List< T > &  l)
inline

◆ operator+=() [2/2]

List<T>& operator+= ( const T &  h)
inline

◆ operator-=() [1/2]

List<T>& operator-= ( const List< T > &  l)
inline

◆ operator-=() [2/2]

List<T>& operator-= ( const T &  h)
inline

◆ operator=()

List& operator= ( const List< T, E, A > &  list)
inline

◆ operator==()

bool operator== ( const List< T > &  l) const
inline

◆ operator[]() [1/2]

T& operator[] ( int  k)
inline

◆ operator[]() [2/2]

const T& operator[] ( int  k) const
inline

◆ pop()

T pop ( void  )
inline

◆ push()

void push ( const T &  i)
inline

◆ remove() [1/2]

void remove ( const T &  item)
inline

Remove the given item from the list or just one if the list contains many items equals to the given one. The item type T must support the equality / inequality operators.

Warning
This method may break iterator work!
Parameters
itemItem to remove.

References List< T, E, A >::first(), List< T, E, A >::isEmpty(), and List< T, E, A >::removeFirst().

Referenced by ListSet< T, C, A >::diff(), ListSet< T, C, A >::meet(), List< T, E, A >::operator-=(), SortedList< T, C, A >::remove(), and List< T, E, A >::removeAll().

◆ remove() [2/2]

void remove ( PrecIter iter)
inline

◆ removeAll()

void removeAll ( const C &  items)
inline

◆ removeFirst()

void removeFirst ( void  )
inline

Remove the first item from the list.

Warning
It is an error to call this method if the list is empty.
This method may break iterator work!

References SLList::removeFirst().

Referenced by List< T, E, A >::pop(), List< T, E, A >::remove(), and SortedList< T, C, A >::removeFirst().

◆ removeLast()

void removeLast ( void  )
inline

Remove the last item from the list. Remark that this method is really inefficient. Its working time is in O(n), n number of nodes in the list. Use it only with small list or revert to more powerful data structures.

Warning
It is an error to call this method if the list is empty.
This method may break iterator work!

References SLList::removeLast().

Referenced by SortedList< T, C, A >::removeLast().

◆ reset()

void reset ( void  )
inline

◆ set()

void set ( const Iter pos,
const T &  item 
)
inline

change the value of an element of the list.

Parameters
posIterator on the element to set.
itemValue to set.
Warning
The iterator must point to an actual element, not the end of the list.

Referenced by SortedList< T, C, A >::set().

◆ top()

const T& top ( void  ) const
inline

Member Data Documentation

◆ null

List< T, E, A > null
static

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