University of Sheffield   

    The Simons
    Component Library

Introduction   Class Hierarchy   Class Listing   Index of Classes   Index of Methods   Header Files  

List Class Reference

#include <List.h>

Inheritance diagram for List:

Sequence Collection Object List of all members.

Detailed Description

List: a singly-linked list of objects, in sequential order.

A List is a kind of Sequence that stores its elements in a chain of linked cells. List is the more efficient kind Sequence to use if elements are frequently inserted and removed at the front or middle of the List. If elements are only inserted and removed at the back, or accessed randomly, then a Vector should be used instead. A List is indexed from 0..n-1 where n is the size() of the List. Traversing a List in the forwards direction is efficient. If elements are visited in reverse, or random order, then a Vector should be used instead. A chain of links is used to store elements and new links are created and deleted on demand.


Public Member Functions

 List ()
 Construct an empty List.

virtual ~List ()
 Release a List.

 List (CollectionID)
 Copy this List from another Collection.

virtual ObjectID clone () const
 Clone a dynamic shallow copy of this List.

Natural size () const
 Return the size of this List.

virtual ObjectID first () const
 Return the first Object in this List.

virtual Void addFirst (ObjectID)
 Add an Object to the front of this List.

virtual Void removeFirst ()
 Remove an Object from the front of this List.

virtual ObjectID getAt (Integer) const
 Get the Object at an indexed position.

virtual Void putAt (Integer, ObjectID)
 Replace an Object at an indexed position.

virtual Void addAt (Integer, ObjectID)
 Insert an Object at an indexed position.

virtual Void removeAt (Integer)
 Remove an Object at an indexed position.


Constructor & Destructor Documentation

List::List  ) 
 

Construct an empty List.

Allocates a dummy link as the head of the List, to reduce the number of null pointer checks and to make insertions and deletions more efficient.

Returns:
an empty List.

List::~List  )  [virtual]
 

Release a List.

Walks through the links from the head and deletes each link.

List::List CollectionID  other  ) 
 

Copy this List from another Collection.

Allocates a dummy link as the head of the List, then uses addAll() to include the other Collection.

Parameters:
other - the other Collection.
Returns:
a List containing the elements of the Collection.


Member Function Documentation

Void List::addAt Integer  index,
ObjectID  object
[virtual]
 

Insert an Object at an indexed position.

Splices in a new link at the index position, such that all existing elements from the index position to the end of the List are displaced upward. This is efficient for repeated insertions at the same index, or at continuously incrementing indices. To splice another Sequence into this List, iterate through its elements with item() and insert them at an incrementing index. To splice another Sequence in reverse order, insert all of its elements at the same index in this List. May throw an OutOfBounds exception if the index is out of bounds.

Parameters:
index - an Integer index.
object - the Object to be inserted.

Reimplemented from Sequence.

Void List::addFirst ObjectID  obj  )  [virtual]
 

Add an Object to the front of this List.

More efficient implementation than the inherited version.

Parameters:
obj - the Object to be added.

Reimplemented from Sequence.

ObjectID List::clone  )  const [virtual]
 

Clone a dynamic shallow copy of this List.

The resulting List manages a separate chain of links, but shares the Object elements of this List.

Returns:
a shallow copy of this List.

Reimplemented from Object.

ObjectID List::first  )  const [virtual]
 

Return the first Object in this List.

More efficient implementation than the inherited version. May throw an OutOfBounds exception, if the List is empty.

Returns:
the first Object in this List.

Reimplemented from Sequence.

ObjectID List::getAt Integer  index  )  const [virtual]
 

Get the Object at an indexed position.

May throw an OutOfBounds exception, if the index is out of bounds.

Parameters:
index - an index.
Returns:
the Object at this index.

Reimplemented from Sequence.

Void List::putAt Integer  index,
ObjectID  object
[virtual]
 

Replace an Object at an indexed position.

May throw an OutOfBounds exception, if the index is out of bounds.

Parameters:
index - an index.
object - the Object to be stored at this index.

Reimplemented from Sequence.

Void List::removeAt Integer  index  )  [virtual]
 

Remove an Object at an indexed position.

Excises a link at the index position, such that all existing elements above the index position to the end of the List are displaced downward. This is efficient for repeated removals at the same index. To excise a sub - Sequence from this List, remove elements repeatedly at the same index in this List. May raise an OutOfRange exception, if the index is out of bounds.

Reimplemented from Sequence.

Void List::removeFirst  )  [virtual]
 

Remove an Object from the front of this List.

More efficient implementation than the inherited version. May throw an OutOfBounds exception, if the List is empty.

Reimplemented from Sequence.

Natural List::size  )  const [virtual]
 

Return the size of this List.

Returns the length of the List.

Returns:
the element count.

Reimplemented from Collection.


The documentation for this class was generated from the following files:
Generated on Fri May 5 17:17:17 2006 for The Simons Component Library by doxygen1.3