University of Sheffield   

    The Simons
    Component Library

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

Sequence Class Reference

#include <Sequence.h>

Inheritance diagram for Sequence:

Collection Object List String Vector List of all members.

Detailed Description

Sequence: the abstract superclass of all sequential collections.

The Sequence class is an intermediate class in the collections hierarchy and the superclass of all sequences, such as Vector, List and String. In a Sequence, the inserted order of elements is significant. Adding new elements appends these to the end of the Sequence. Elements are extrinsically ordered, according to their index position in a Sequence. The notions of a first and last element are meaningful. Elements may be visited in order via an index in the range 0..n-1, where n is the size of the Sequence. Sequence defines the interface for accessing, inserting, removing and replacing elements at index positions. Comparing two Sequences performs a lexicographic comparison of their elements. Hashing on a Sequence is sensitive to both the values and the order of the elements.


Public Member Functions

 Sequence ()
 Create an empty Sequence.

virtual ~Sequence ()
 Release a Sequence.

virtual Natural hash () const
 Return a quasi-unique hash code for this Sequence.

virtual Order compare (ObjectID) const
 Compare this Sequence with another Object.

Order compare (SequenceID) const
 Compare this Sequence with another Sequence.

virtual ObjectID item (Integer) const
 Select an Object contained in this Sequence.

virtual Void add (ObjectID)
 Add an Object to this Sequence.

virtual ObjectID first () const
 Return the first Object in the Sequence.

virtual ObjectID last () const
 Return the last Object in the Sequence.

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

virtual Void addLast (ObjectID)
 Add an Object to the back of the Sequence.

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

virtual Void removeLast ()
 Remove an Object from the back of the Sequence.

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.


Protected Member Functions

 Sequence (const Sequence &)
 Copy another Sequence.


Constructor & Destructor Documentation

Sequence::Sequence const Sequence &  other  )  [protected]
 

Copy another Sequence.

This secret copy constructor is provided to ensure that copying a Sequence faithfully copies the parent Collection.

Parameters:
other - the other Sequence to copy.
Returns:
- a shallow copy of the Sequence.

Sequence::Sequence  ) 
 

Create an empty Sequence.

Returns:
an empty Sequence.

Sequence::~Sequence  )  [virtual]
 

Release a Sequence.


Member Function Documentation

Void Sequence::add ObjectID  object  )  [virtual]
 

Add an Object to this Sequence.

Part of the Collection protocol, which supports the addition of elements. Sequence defines add(object) to mean the same thing as addLast(object), since the order of element insertion is significant.

Parameters:
object - the Object to be added.

Reimplemented from Collection.

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

Insert an Object at an indexed position.

All existing elements from the index position and above increase their index by one. This method is abstract in Sequence, since different types of Sequence access their elements in different ways.

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

Reimplemented in List, String, and Vector.

Void Sequence::addFirst ObjectID  object  )  [virtual]
 

Add an Object to the front of the Sequence.

By default, Sequence defines addFirst(object) to mean the same thing as addAt(0, object). This method is redefined in those descendants of Sequence, which can insert more efficiently at the front.

Parameters:
object - the Object to be added.

Reimplemented in List.

Void Sequence::addLast ObjectID  object  )  [virtual]
 

Add an Object to the back of the Sequence.

By default, Sequence defines addLast(object) to mean the same thing as addAt(size(), object). This method is redefined in those descendants of Sequence, which can insert more efficiently at the back.

Parameters:
object - the Object to be added.

Reimplemented in Vector.

Order Sequence::compare SequenceID  other  )  const
 

Compare this Sequence with another Sequence.

A lexicographic comparison, which compares all elements pairwise, returning an Order based on the first element comparison which is not EQUAL, according to compare(). If all elements are pairwise EQUAL up to the end of either Sequence, this Sequence is considered LESS than, EQUAL to, or MORE than the other Sequence if it is respectively shorter, the same length, or longer than the other one. If any of the elements are incomparable, the comparison is undefined and the result is NONE.

Parameters:
other - the other Sequence.
Returns:
an Order in: { NONE, LESS, EQUAL, MORE }

Order Sequence::compare ObjectID  object  )  const [virtual]
 

Compare this Sequence with another Object.

Generic comparison that tries to convert the other Object into a Sequence and then proceeds to compare according to the lexicographic ordering of elements. If the other Object is not a Sequence, the comparison is undefined and the result is NONE.

Parameters:
object - the other Object.
Returns:
an Order in { NONE, LESS, EQUAL, MORE }.

Reimplemented from Object.

Reimplemented in String.

ObjectID Sequence::first  )  const [virtual]
 

Return the first Object in the Sequence.

By default, Sequence defines first() to mean the same thing as getAt(0). This method is redefined more efficiently in some descendants of Sequence. May throw an OutOfRange exception if the Sequence is empty.

Returns:
the first Object in the Sequence.

Reimplemented in List.

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

Get the Object at an indexed position.

This method is abstract in Sequence, since different types of Sequence access their elements in different ways.

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

Reimplemented in List, String, and Vector.

Natural Sequence::hash  )  const [virtual]
 

Return a quasi-unique hash code for this Sequence.

Uses the famous P J Weinberger hashing algorithm from Aho, Sethi and Ullman, p436. The result is based both on the values and the ordering of the elements. For each element, the result so far is shifted left by 4 bits, then the next element hash code is added. If this sets any of the four high-order bits, these are stripped, shifted right by 24 bits and XORed with the result.

Returns:
a quasi-unique hash code.

Reimplemented from Object.

Reimplemented in String.

ObjectID Sequence::item Integer  index  )  const [virtual]
 

Select an Object contained in this Sequence.

Part of the Collection protocol, which supports iteration over elements via an index. Sequence defines item(index) to mean the same thing as getAt(index), since all Sequences support access via an index. May throw an OutOfRange exception if the index is out of range.

Parameters:
index - an index into this Sequence.
Returns:
the Object found at the index.

Reimplemented from Collection.

ObjectID Sequence::last  )  const [virtual]
 

Return the last Object in the Sequence.

By default, Sequence defines last() to mean the same thing as getAt(size() -1). This method is redefined more efficiently in some descendants of Sequence. May throw an OutOfRange exception if the Sequence is empty.

Returns:
the last Object in the Sequence.

Reimplemented in Vector.

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

Replace an Object at an indexed position.

This method is abstract in Sequence, since different types of Sequence access their elements in different ways.

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

Reimplemented in List, String, and Vector.

Void Sequence::removeAt Integer  index  )  [virtual]
 

Remove an Object at an indexed position.

All existing elements above the index position reduce their index by one. This method is abstract, in Sequence, since different types of Sequence access their elements in different ways.

Parameters:
index - an index.

Reimplemented in List, String, and Vector.

Void Sequence::removeFirst  )  [virtual]
 

Remove an Object from the front of the Sequence.

By default, Sequence defines removeFirst() to mean the same thing as removeAt(0). This method is redefined in those descendants of Sequence, which can remove more efficiently from the front.

Reimplemented in List.

Void Sequence::removeLast  )  [virtual]
 

Remove an Object from the back of the Sequence.

By default, Sequence defines removeLast() to mean the same thing as removeAt(size() -1). This method is redefined in those descendants of Sequence, which can remove more efficiently from the back.

Reimplemented in Vector.


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