![]() |
The Simons
|
#include <Vector.h>
Inheritance diagram for Vector:
A Vector is a kind of Sequence that stores its elements in a single memory block. Vector is the more efficient kind Sequence to use if elements are randomly accessed by their index, or if elements are only added and removed from the back of the Vector. If elements are frequently inserted and removed at the front or in the middle, then a List should be used instead. A Vector is indexed from 0..n-1 where n is the size() of the Vector. The array used to store elements may expand to accommodate more elements.
Public Member Functions | |
Vector () | |
Construct an empty Vector. | |
Vector (Natural) | |
Construct an empty Vector with a suggested capacity. | |
Vector (CollectionID) | |
Copy this Vector from another Collection. | |
virtual | ~Vector () |
Release a Vector. Deletes the array used for the storage of elements. | |
virtual ObjectID | clone () const |
Clone a shallow copy of this Vector. | |
Natural | size () const |
Return the size of this Vector. | |
virtual ObjectID | last () const |
Return the last Object in this Vector. | |
virtual Void | addLast (ObjectID) |
Add an Object to the back of this Vector. | |
virtual Void | removeLast () |
Remove an Object from the back of this Vector. | |
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. |
|
Construct an empty Vector. Allocates an array of the default capacity, which may eventually expand if more capacity is later required. Use this constructor if the required capacity is unknown.
|
|
Construct an empty Vector with a suggested capacity. Allocates an array of the specified capacity, which may eventually expand if more capacity is later required. Use this constructor if the required capacity is known.
|
|
Copy this Vector from another Collection. Allocates an array of sufficient capacity to store all the elements of the other Collection, then uses addAll() to include the other Collection. This Vector may eventually expand, if more capacity is later required.
|
|
Release a Vector. Deletes the array used for the storage of elements.
|
|
Insert an Object at an indexed position. All existing elements from the index position to the end of the Vector are moved up by one position and the new Object is inserted at the vacant index position. If the capacity of the Vector is exceeded, a larger memory block is allocated. This method copies object references, with a linear time penalty. To avoid this penalty when making frequent insertions, a List should be used instead. May raise an OutOfRange exception, if the index is out of bounds.
Reimplemented from Sequence. |
|
Add an Object to the back of this Vector. More efficient implementation than the inherited version.
Reimplemented from Sequence. |
|
Clone a shallow copy of this Vector. The resulting Vector manages a separate array for storage, but shares the Object elements of this Vector.
Reimplemented from Object. |
|
Get the Object at an indexed position. May raise an OutOfRange exception if the index is out of bounds.
Reimplemented from Sequence. |
|
Return the last Object in this Vector. More efficient implementation than the inherited version. May raise an OutOfRange execption, if the Vector is empty.
Reimplemented from Sequence. |
|
Replace an Object at an indexed position. May raise an OutOfRange exception if the index is out of bounds.
Reimplemented from Sequence. |
|
Remove an Object at an indexed position. All existing elements from the index+1 position to the end of the Vector are moved down by one position. The removed Object reference is overwritten. This method copies object references, with a linear time penalty. To avoid this penalty when making frequent removals, a List should be used instead. May raise an OutOfRange exception, if the index is out of bounds.
Reimplemented from Sequence. |
|
Remove an Object from the back of this Vector. More efficient implementation than the inherited version. May raise an OutOfRange execption, if the Vector is empty. Reimplemented from Sequence. |
|
Return the size of this Vector. Counts the number of Object elements held in this Vector.
Reimplemented from Collection. |