#include <MAUtil/Vector.h>
Performance characteristics are as follows:
Access to any element by index is very fast (constant time).
add(), insert() and remove() at the end of the vector are fast (constant time amortized over linear time).
insert() and remove() anywhere else are slow, (linear time).
Public Types | |
typedef Type * | iterator |
Defines a typesafe iterator for the template instance. | |
typedef const Type * | const_iterator |
Public Member Functions | |
Vector (int initialCapacity=4) | |
Constructs the Vector and sets its capacity to initialCapacity. | |
~Vector () | |
Destructor. | |
Vector & | operator= (const Vector &other) |
void | add (const Type &val) |
Adds an element to the end of the Vector. | |
void | add (const Type *ptr, int num) |
Adds several elements to the end of the Vector. | |
void | remove (iterator i) |
Removes the element pointed to by iterator i. | |
void | remove (int index) |
Removes the element at index. | |
void | insert (int index, Type t) |
Inserts the element at index, moving all existing elements beginning at 'index' one step forward. | |
int | size () const |
Returns the number of elements. | |
void | resize (int newSize) |
Resizes the Vector to contain size elements. | |
void | reserve (int newCapacity) |
Reserves space in the Vector. | |
void | clear () |
Clears the Vector, setting its size to 0 but not altering its capacity. | |
bool | empty () const |
Returns true iff the Vector is empty(). | |
int | capacity () const |
Returns the Vector's current capacity. | |
iterator | begin () |
Returns an iterator pointing to the first element of the Vector. | |
iterator | end () |
Returns an iterator pointing beyond the last element of the Vector. | |
const_iterator | begin () const |
Returns an iterator pointing to the first element of the Vector. | |
const_iterator | end () const |
Returns an iterator pointing beyond the last element of the Vector. | |
Type & | operator[] (int index) |
Returns a reference to the element at index. No range-checking is done. | |
const Type & | operator[] (int index) const |
Returns a const reference to the element at index. No range-checking is done. | |
const Type * | pointer () const |
Returns a const pointer to the Vector's storage array. | |
Type * | pointer () |
Returns a pointer to the Vector's storage array. | |
Protected Attributes | |
int | mSize |
int | mCapacity |
Type * | mData |
|
Defines a typesafe iterator for the template instance.
|
|
|
|
Constructs the Vector and sets its capacity to initialCapacity.
|
|
Destructor.
|
|
Copies the other vector.
|
|
Adds an element to the end of the Vector.
|
|
Adds several elements to the end of the Vector.
|
|
Removes the element pointed to by iterator i.
|
|
Removes the element at index.
|
|
Inserts the element at index, moving all existing elements beginning at 'index' one step forward.
|
|
Returns the number of elements.
|
|
Resizes the Vector to contain size elements.
|
|
Reserves space in the Vector.
|
|
Clears the Vector, setting its size to 0 but not altering its capacity.
|
|
Returns true iff the Vector is empty().
|
|
Returns the Vector's current capacity.
|
|
Returns an iterator pointing to the first element of the Vector.
|
|
Returns an iterator pointing beyond the last element of the Vector.
|
|
Returns an iterator pointing to the first element of the Vector.
|
|
Returns an iterator pointing beyond the last element of the Vector.
|
|
Returns a reference to the element at index. No range-checking is done.
|
|
Returns a const reference to the element at index. No range-checking is done.
|
|
Returns a const pointer to the Vector's storage array.
|
|
Returns a pointer to the Vector's storage array.
|
|
|
|
|
|
|