Chombo + EB + MF
3.2
|
A Doubly-Linked List Class. More...
#include <List.H>
Public Member Functions | |
List () | |
Construct an empty List<T>. More... | |
List (bool usePool) | |
List (const List< T > &rhs) | |
The copy constructor. More... | |
List< T > & | operator= (const List< T > &rhs) |
The assignment operator. More... | |
~List () | |
The destructor. More... | |
void | prepend (const T &value) |
Adds a copy of the value to the beginning of the List<T>. More... | |
void | append (const T &value) |
Adds a copy of the value to the end of the List<T>. More... | |
void | add (const T &value) |
Adds a copy of the value to the end of the List<T>. More... | |
void | join (const List< T > &src) |
Appends a copy of all items in List<T> src to this List<T>. More... | |
void | catenate (List< T > &src) |
Appends a copy of all items in List<T> src to this List<T>. More... | |
void | clear () |
Removes all objects from the List<T>. More... | |
List< T > * | copy () const |
Returns a copy of this List<T> on the heap. More... | |
T & | firstElement () const |
Returns a reference to the first element in the List<T>. More... | |
T & | lastElement () const |
Returns a reference to the last element in the List<T>. More... | |
bool | includes (const T &value) const |
Returns true if the List<T> contains an object identical to value. More... | |
bool | operator== (const List< T > &rhs) const |
Returns true if the this and rhs are memberwise equal. More... | |
bool | operator!= (const List< T > &rhs) const |
Returns true if the this and rhs are not equal. More... | |
bool | isEmpty () const |
Returns true if the List<T> is empty. More... | |
bool | isNotEmpty () const |
Returns true if the List<T> is not empty. More... | |
int | length () const |
Returns the number of objects in the List<T>. More... | |
void | removeFirst () |
Removes the first element in the List<T>. More... | |
void | removeLast () |
Removes the last element in the List<T>. More... | |
const T & | operator[] (const ListIterator< T > &li) const |
Returns reference to object pointed to by the ListIterator<T>. More... | |
T & | operator[] (const ListIterator< T > &li) |
Returns reference to object pointed to by the ListIterator<T>. More... | |
void | remove (const T &value) |
Removes all objects in the List<T> equal to value. More... | |
void | remove (const List< T > &lst) |
Removes all objects in the List<T> equal to any of the values in lst. More... | |
void | remove (ListIterator< T > &lit) |
Removes the object pointed to by the ListIterator<T>. More... | |
void | transfer (ListIterator< T > &lit) |
Transfer the object pointed to by lit from the List<T> lit is associated with to this one. More... | |
void | replace (ListIterator< T > &li, const T &val) |
Replace the value pointed to by the ListIterator<T> by val. More... | |
void | addAfter (ListIterator< T > &lit, const T &val) |
Insert val into List<T> after the object pointed to by lit. More... | |
void | addBefore (ListIterator< T > &lit, const T &val) |
Insert val into List<T> before the object pointed to by lit. More... | |
ListIterator< T > | listIterator () const |
Returns a ListIterator<T> to the first object in this List<T>. More... | |
ListIterator< T > | first () const |
Returns a ListIterator<T> to the first object in this List<T>. More... | |
ListIterator< T > | last () const |
Returns a ListIterator<T> to the last object in this List<T>. More... | |
void | sort () |
sort according to operator< (note: currently implemented with BubbleSort) More... | |
void | checkLinks () const |
Protected Member Functions | |
void | remove (ListLink< T > *ln) |
void | removeLink (ListLink< T > *ln) |
ListLink< T > * | addBefore (ListLink< T > *ln, const T &val) |
ListLink< T > * | addAfter (ListLink< T > *ln, const T &val) |
Protected Attributes | |
ListLink< T > * | head |
ListLink< T > * | tail |
bool | m_usePool |
Static Protected Attributes | |
static Pool | linkPool |
Friends | |
class | ListIterator< T > |
A Doubly-Linked List Class.
The List<T> class is a template class that implements a doubly-linked list of objects. A List<T> is a useful container class when the number of objects in the collection is not known ahead of time. A List<T> can contain an arbitrary number of elements; operations such as insertion, deletion, and catenation are easily implemented and inexpensive.
The only difficulty when defining a list class is devising a mechanism to access the elements. In an array, an element is accessed using an integer index. Since the elements in a List<T> are ordered by position, we could define an integer indexing operation that walks along the List<T> links from the beginning until the numbered element is found. Unfortunately, this would be very inefficient when accessing elements near the end of a long list. Another solution is to allow user access to the individual link objects that contain the element as well as the forward and backward pointers. This is not a satisfactory solution since it allows user access to the internal representation of the class. The solution chosen is to define a ListIterator<T> template class.
Think of a ListIterator<T> as a pointer to an object in the List<T>. You can access the element currently pointed to by the iterator, move the iterator forward and backward through the List<T>, and use it as a mechanism to define where elements should be inserted and deleted. If the iterator is moved off the end of the list it behaves as a null pointer.
This is a concrete class, not a polymorphic one.
The assignment operator.
|
inline |
Adds a copy of the value to the beginning of the List<T>.
|
inline |
Adds a copy of the value to the end of the List<T>.
Referenced by List< P >::add(), buildLocalIndexList(), List< P >::join(), ListBox< T >::linearIn(), BinFab< T >::linearIn(), List< P >::List(), and List< P >::operator=().
void List< T >::add | ( | const T & | value | ) |
Adds a copy of the value to the end of the List<T>.
Referenced by ListBox< T >::addItems(), ListBox< T >::getInvalid(), ListBox< T >::getItems(), and readParticlesFromHDF().
Appends a copy of all items in List<T> src to this List<T>.
Referenced by ListBox< T >::getItems().
Appends a copy of all items in List<T> src to this List<T>.
This differs from join() in that it unlinks the objects from the List<T> src and glues them to the end of this List<T>, leaving List<T> src empty. This is more efficient that join() if src is no longer needed.
Referenced by ParticleData< P >::fillGhosts(), ListBox< T >::getItemsDestructive(), and BinFab< T >::transfer().
void List< T >::clear | ( | ) |
Removes all objects from the List<T>.
Referenced by ParticleData< P >::clear(), BinFab< T >::linearIn(), BinFab< T >::linearOutDestructive(), List< P >::operator=(), and List< P >::~List().
Returns a copy of this List<T> on the heap.
It is the user's responsibility to delete this when no longer needed.
|
inline |
Returns a reference to the first element in the List<T>.
|
inline |
Returns a reference to the last element in the List<T>.
bool List< T >::includes | ( | const T & | value | ) | const |
Returns true if the List<T> contains an object identical to value.
Type T must have an operator==() defined, or be an intrinsic type.
Returns true if the this and rhs are memberwise equal.
Lists are memberwise equal if he two lists are the same size and each of the elements in the list compare equal. Type T must have an operator==() defined, or be an intrinsic type.
Referenced by List< P >::operator!=().
Returns true if the this and rhs are not equal.
|
inline |
Returns true if the List<T> is empty.
Referenced by List< P >::catenate(), ParticleData< P >::isClosed(), List< P >::isNotEmpty(), List< P >::List(), and ParticleData< P >::remapOutcast().
|
inline |
Returns true if the List<T> is not empty.
Referenced by BinFab< T >::addItems(), ListBox< T >::addItems(), BinFab< T >::addItemsDestructive(), ListBox< T >::addItemsDestructive(), BlockBaseRegister< FArrayBox >::createDstBoxLayout(), BlockBaseRegister< FArrayBox >::createExchangeBoxLayout(), BlockBaseRegister< FArrayBox >::createSrcBoxLayout(), and BinFab< T >::reBin().
int List< T >::length | ( | ) | const |
Returns the number of objects in the List<T>.
Referenced by ListBox< T >::linearOut(), BinFab< T >::linearOut(), ListBox< T >::linearOutDestructive(), BinFab< T >::linearOutDestructive(), ParticleData< P >::numOutcastLocal(), ParticleData< P >::numParticlesLocal(), List< P >::operator==(), and writeParticlesToHDF().
|
inline |
Removes the first element in the List<T>.
|
inline |
Removes the last element in the List<T>.
|
inline |
Returns reference to object pointed to by the ListIterator<T>.
|
inline |
Returns reference to object pointed to by the ListIterator<T>.
void List< T >::remove | ( | const T & | value | ) |
Removes all objects in the List<T> equal to value.
Referenced by BlockBaseRegister< FArrayBox >::createDstBoxLayout(), BlockBaseRegister< FArrayBox >::createExchangeBoxLayout(), BlockBaseRegister< FArrayBox >::createSrcBoxLayout(), and BinFab< T >::reBin().
Removes all objects in the List<T> equal to any of the values in lst.
void List< T >::remove | ( | ListIterator< T > & | lit | ) |
Removes the object pointed to by the ListIterator<T>.
void List< T >::transfer | ( | ListIterator< T > & | lit | ) |
Transfer the object pointed to by lit from the List<T> lit is associated with to this one.
Referenced by ListBox< T >::addItemsDestructive(), collectValidParticles(), ListBox< T >::getInvalidDestructive(), ListBox< T >::getItemsDestructive(), and BinFab< T >::reBin().
|
inline |
Replace the value pointed to by the ListIterator<T> by val.
|
inline |
Insert val into List<T> after the object pointed to by lit.
Referenced by List< P >::addAfter(), and List< P >::append().
|
inline |
Insert val into List<T> before the object pointed to by lit.
Referenced by List< P >::addBefore(), and List< P >::prepend().
|
inline |
Returns a ListIterator<T> to the first object in this List<T>.
|
inline |
Returns a ListIterator<T> to the first object in this List<T>.
Referenced by BlockBaseRegister< FArrayBox >::createDstBoxLayout(), BlockBaseRegister< FArrayBox >::createExchangeBoxLayout(), and BlockBaseRegister< FArrayBox >::createSrcBoxLayout().
|
inline |
Returns a ListIterator<T> to the last object in this List<T>.
void List< T >::sort | ( | ) |
sort according to operator< (note: currently implemented with BubbleSort)
void List< T >::checkLinks | ( | ) | const |
A helper function for removing nodes.
Referenced by List< P >::remove(), and List< P >::transfer().
|
protected |
A helper function for adding nodes.
|
protected |
A helper function for adding nodes.
|
friend |
Our good and trusted friend.
The head of the list.
Referenced by List< P >::addAfter(), List< P >::addBefore(), List< P >::catenate(), List< P >::checkLinks(), List< P >::clear(), List< P >::first(), List< P >::firstElement(), List< P >::isEmpty(), List< P >::List(), List< P >::listIterator(), List< P >::prepend(), List< P >::removeFirst(), List< P >::removeLink(), List< P >::sort(), and List< P >::transfer().
The tail of the list.
Referenced by List< P >::addAfter(), List< P >::addBefore(), List< P >::append(), List< P >::catenate(), List< P >::checkLinks(), List< P >::clear(), List< P >::isEmpty(), List< P >::last(), List< P >::lastElement(), List< P >::List(), List< P >::removeLast(), List< P >::removeLink(), List< P >::sort(), and List< P >::transfer().
A new member that hopefully will make our List snappier. In particular when you have a large number of items, like in Particle code.
Referenced by List< P >::addAfter(), List< P >::addBefore(), List< P >::clear(), and List< P >::remove().
|
protected |
Referenced by List< P >::addAfter(), List< P >::addBefore(), List< P >::clear(), and List< P >::remove().