QSDK 1.1 Documentation
Main Page | Modules | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

Utils::Vector< T > Struct Template Reference
[Collection classes]

#include <Q/vector.h>

Inheritance diagram for Utils::Vector< T >:

Utils::VectorBase Utils::OrderedVector< T, C > List of all members.

Public Member Functions

 Vector ()
 Vector (const Vector< T > &v)
 Vector (size_t n)
 ~Vector ()
size_t size () const
size_t space () const
size_t add (const T &e)
void add (const Vector< T > &v)
bool locateLast (const T &e, size_t &i) const
bool intern (const T &e, size_t &i)
void insert (const T &e, size_t i)
void insert (const Vector< T > &v, size_t i)
bool removeAt (size_t i)
bool removeAt (size_t start, size_t end)
bool remove (const T &e)
bool remove (const Vector< T > &v)
bool member (const T &t) const
void empty ()
void clear ()
int compare (const Vector< T > &v) const
void consume (Vector< T > &v)
void subtract (const Vector< T > &v, Vector< T > &result) const
void intersect (const Vector< T > &v, Vector< T > &result) const
Vector< T > & operator+= (const Vector< T > &v)
Vector< T > & operator-= (const Vector< T > &v)
int operator== (const Vector< T > &v) const
const T & first () const
const T & last () const
void at (size_t i, const T &t)
void sizeTo (size_t n)
void sizeToExact (size_t n)
void spaceTo (size_t n)
Vector< T > & operator= (const Vector< T > &v)
void slice (size_t start, size_t end, Vector< T > &result) const
size_t instanceSize () const
T & operator[] (size_t i)
const T & operator[] (size_t i) const
T & at (size_t i)
const T & at (size_t i) const
bool locate (const T &e, size_t &i) const
bool locateFirst (const T &e, size_t &i) const

Protected Member Functions

void init ()
void size (size_t s)
void resizeFor (size_t)
void purge ()
 DECL_OPERATORS (T)

Protected Attributes

size_t space_
T * v_

Detailed Description

template<class T>
struct Utils::Vector< T >

The template Vector<T> is an extensible array-like container object. The argument to the template is the type of an individual element of the vector. This type must support a number of features required by the template implementation. It must have a default constructor (i.e. one which takes no arguments), and it must support the following C++ operators, or equivalents: Note that all C++ primitive types (such as int and char) automatically fulfil these constraints. Elements in a Vector<T> are stored in a contiguous array in memory and as such, operations such as Vector<T>::operator[]() and Vector<T>::add() (in the case where the vector has spare memory available, i.e. when the value returned by Vector<T>::space() is greater than the value returned by Vector<T>::size()) are performed in a constant amount of time, independent of the array. Operations such as Vector<T>::locate(), Vector<T>::remove() and Vector<T>::insert() are typically performed in an amount of time proportional to the size of the vector.
See also:
OrderedVector<T,C>


Constructor & Destructor Documentation

template<class T>
Utils::Vector< T >::Vector  )  [inline]
 

Create a new empty vector.

template<class T>
Utils::Vector< T >::Vector const Vector< T > &  v  )  [inline]
 

Create a copy of an existing vector.

template<class T>
Utils::Vector< T >::Vector size_t  n  )  [inline]
 

Create a new vector of size 0 with space allocated for n objects.

See also:
space().

template<class T>
Utils::Vector< T >::~Vector  )  [inline]
 

Destroy the vector.


Member Function Documentation

template<class T>
void Utils::Vector< T >::add const Vector< T > &  v  ) 
 

Append the contents of an existing vector, v, to this one.

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
size_t Utils::Vector< T >::add const T &  e  ) 
 

Append a single element e to the end of the vector, returning the index of the new element. Vectors are stable, in the sense that they preserve order. add(a) then add(b) will store a before b in the list.

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
void Utils::Vector< T >::at size_t  i,
const T &  t
[inline]
 

Set the i th element of this vector to t.

template<class T>
const T& Utils::Vector< T >::at size_t  i  )  const [inline]
 

Return a reference to the i th element of the vector.

template<class T>
T& Utils::Vector< T >::at size_t  i  )  [inline]
 

Return a reference to the i th element of the vector.

template<class T>
void Utils::Vector< T >::clear  )  [inline]
 

Discard all elements from this vector, but keep the space constant.

template<class T>
int Utils::Vector< T >::compare const Vector< T > &  v  )  const
 

Return zero if this vector has the same value as the vector v, or non-zero otherwise.

template<class T>
void Utils::Vector< T >::consume Vector< T > &  v  ) 
 

Move the underlying storage of vector v to this vector, freeing any existing storage and leaving v empty.

template<class T>
void Utils::Vector< T >::empty  )  [inline]
 

Discard all elements from this vector, resetting the size to zero.

template<class T>
const T& Utils::Vector< T >::first  )  const [inline]
 

Return a reference to the first element of the vector.

template<class T>
void Utils::Vector< T >::insert const Vector< T > &  v,
size_t  i
 

The contents of the vector v are inserted into this vector at index i.

template<class T>
void Utils::Vector< T >::insert const T &  e,
size_t  i
 

The element e is inserted into the vector at index i.

template<class T>
size_t Utils::Vector< T >::instanceSize  )  const
 

Return the amount of memory used by this vector in bytes.

template<class T>
bool Utils::Vector< T >::intern const T &  e,
size_t &  i
 

If the element e is not a member of the vector it is appended to the end of the vector and true is returned, otherwise false is returned. The value of i is set to the index of the existing or new element.

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
void Utils::Vector< T >::intersect const Vector< T > &  v,
Vector< T > &  result
const
 

Calculate the set intersection of this vector with v, i.e. the set of elements which appear in both this vector and v. The vector result is first emptied and the elements from the intersection set are added to it.

template<class T>
const T& Utils::Vector< T >::last  )  const [inline]
 

Return a reference to the last element of the vector.

template<class T>
bool Utils::Vector< T >::locate const T &  e,
size_t &  i
const
 

Search for the first element in the vector that is equal to e. If such an element is found, i is set to the index of the element and true is returned, otherwise false is returned and i is set to the current size of the vector.

See also:
Vector<T>::member()

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
bool Utils::Vector< T >::locateFirst const T &  e,
size_t &  i
const [inline]
 

Search for the first element in the vector that is equal to e. If such an element is found, i is set to the index of the element and true is returned, otherwise false is returned and i is set to the current size of the vector.

See also:
Vector<T>::member()

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
bool Utils::Vector< T >::locateLast const T &  e,
size_t &  i
const
 

Search for the last element in the vector equal to e. Set i to the index of the element if one is found, or 0 otherwise.

Returns:
true if an element equal to e is found.

false if no element equal to e is found.

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
bool Utils::Vector< T >::member const T &  t  )  const [inline]
 

Return true if element t is a member of this vector, false otherwise.

See also:
Vector<T>::locate()

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
Vector<T>& Utils::Vector< T >::operator+= const Vector< T > &  v  )  [inline]
 

Append the contents of the vector v to this one, returning a reference to this vector.

template<class T>
Vector<T>& Utils::Vector< T >::operator-= const Vector< T > &  v  )  [inline]
 

Remove any elements from vector v which appear in this one, returning a reference to this vector.

template<class T>
Vector< T > & Utils::Vector< T >::operator= const Vector< T > &  v  ) 
 

Replace the contents of this vector with the vector v.

template<class T>
int Utils::Vector< T >::operator== const Vector< T > &  v  )  const [inline]
 

Compare this vector with the vector v for equality.

template<class T>
const T& Utils::Vector< T >::operator[] size_t  i  )  const [inline]
 

Return a reference to the i th element of the vector.

template<class T>
T& Utils::Vector< T >::operator[] size_t  i  )  [inline]
 

Return a reference to the i th element of the vector.

template<class T>
bool Utils::Vector< T >::remove const Vector< T > &  v  ) 
 

Remove all elements which appear in vector v from this vector, returning true if all elements from v were removed, false otherwise. Vectors are stable, elements not removed will not be re-ordered.

template<class T>
bool Utils::Vector< T >::remove const T &  e  ) 
 

Remove the first instance of element e from the vector, and return true if any element was removed, false otherwise. Vectors are stable, elements not removed will not be re-ordered.

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
bool Utils::Vector< T >::removeAt size_t  start,
size_t  end
 

Remove all elements with index greater than or equal to start and strictly less than index end from the vector, returning true if any elements were removed or false otherwise. Vectors are stable, elements not removed will not be re-ordered.

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
bool Utils::Vector< T >::removeAt size_t  i  ) 
 

If i is less than the current size of the vector, remove the element at index i from the vector and return true, otherwise return false. Vectors are stable, elements not removed will not be re-ordered.

Reimplemented in Utils::OrderedVector< T, C >.

template<class T>
size_t Utils::Vector< T >::size  )  const [inline]
 

Return the current size of the vector.

template<class T>
void Utils::Vector< T >::sizeTo size_t  n  ) 
 

Set the current size of the vector to n.

template<class T>
void Utils::Vector< T >::sizeToExact size_t  n  ) 
 

Set the current size of the vector to n. The space allocated for the vector is also reduced to n elements.

template<class T>
void Utils::Vector< T >::slice size_t  start,
size_t  end,
Vector< T > &  result
const
 

First empty the vector result and then copy the set of elements in this vector with indices greater than or equal to start and strictly less than end to result.

template<class T>
size_t Utils::Vector< T >::space  )  const [inline]
 

Return the amount of space currently allocated for the vector (i.e. the number of elements that it could store before having to allocate more space).

template<class T>
void Utils::Vector< T >::spaceTo size_t  n  )  [inline]
 

Allocate space for at least n elements, leaving the current size of the vector unchanged.

template<class T>
void Utils::Vector< T >::subtract const Vector< T > &  v,
Vector< T > &  result
const
 

Calculate the set subtraction of this vector with v, i.e. the set of elements that appear in this vector but not in v. The vector result is first emptied and the elements from the subtraction set are added to it.

Return to QSDK documentation Contents page. Contact details for support, information and fault-reporting.
Qube Software Limited © 2000-2004