![]() |
The Simons
|
#include <Sequence.h>
Inheritance diagram for Sequence:
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. |
|
Copy another Sequence. This secret copy constructor is provided to ensure that copying a Sequence faithfully copies the parent Collection.
|
|
Create an empty Sequence.
|
|
Release a Sequence.
|
|
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.
Reimplemented from Collection. |
|
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.
|
|
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.
Reimplemented in List. |
|
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.
Reimplemented in Vector. |
|
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.
|
|
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.
Reimplemented from Object. Reimplemented in String. |
|
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.
Reimplemented in List. |
|
Get the Object at an indexed position. This method is abstract in Sequence, since different types of Sequence access their elements in different ways.
|
|
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.
Reimplemented from Object. Reimplemented in String. |
|
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.
Reimplemented from Collection. |
|
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.
Reimplemented in Vector. |
|
Replace an Object at an indexed position. This method is abstract in Sequence, since different types of Sequence access their elements in different ways.
|
|
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.
|
|
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. |
|
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. |