Regina Calculation Engine
Public Member Functions | Static Public Attributes | Protected Attributes
regina::NFastVector< T > Class Template Reference

A fast but inflexible vector of elements from a given ring T. More...

#include <nfastvector.h>

List of all members.

Public Member Functions

 NFastVector (unsigned newVectorSize)
 Creates a new vector.
 NFastVector (unsigned newVectorSize, const T &initValue)
 Creates a new vector and initialises every element to the given value.
 NFastVector (const NFastVector< T > &cloneMe)
 Creates a new vector that is a clone of the given vector.
 NFastVector (const NVector< T > &cloneMe)
 Creates a new vector that is a clone of the given NVector.
 ~NFastVector ()
 Destroys this vector.
unsigned size () const
 Returns the number of elements in the vector.
const T & operator[] (unsigned index) const
 Returns the element at the given index in the vector.
void setElement (unsigned index, const T &value)
 Sets the element at the given index in the vector to the given value.
bool operator== (const NFastVector< T > &compare) const
 Determines if this vector is equal to the given vector.
void operator= (const NFastVector< T > &cloneMe)
 Sets this vector equal to the given vector.
void operator+= (const NFastVector< T > &other)
 Adds the given vector to this vector.
void operator-= (const NFastVector< T > &other)
 Subtracts the given vector from this vector.
void operator*= (const T &factor)
 Multiplies this vector by the given scalar.
operator* (const NFastVector< T > &other) const
 Calculates the dot product of this vector and the given vector.
void negate ()
 Negates every element of this vector.
norm () const
 Returns the norm of this vector.
elementSum () const
 Returns the sum of all elements of this vector.
void addCopies (const NFastVector< T > &other, const T &multiple)
 Adds the given multiple of the given vector to this vector.
void subtractCopies (const NFastVector< T > &other, const T &multiple)
 Subtracts the given multiple of the given vector to this vector.

Static Public Attributes

static T zero
 Zero in the underlying number system.
static T one
 One in the underlying number system.
static T minusOne
 Negative one in the underlying number system.

Protected Attributes

T * elements
 The internal array containing all vector elements.
T * end
 A pointer just beyond the end of the internal array.

Detailed Description

template<class T>
class regina::NFastVector< T >

A fast but inflexible vector of elements from a given ring T.

This class is intended for heavy computation; as a result it has a streamlined implementation with no virtual methods, but it cannot talk to any vector class other than itself. For a slower but more flexible vector class, see the NVector hierarchy instead.

Like NVector, this class is written with bulky types in mind (such as arbitrary precision integers), so that creations and operations are kept to a minimum.

Precondition:
Type T has a copy constructor. That is, if a and b are of type T, then a can be initialised to the value of b using a(b).
Type T has a default constructor. That is, an object of type T can be declared with no arguments. No specific default value is required.
Type T allows for operators =, ==, +=, -= and *=.
Type T has a long integer constructor. That is, if a is of type T, then a can be initialised to a long integer l using a(l).
An element t of type T can be written to an output stream out using the standard expression out << t.
Python:
Not present.

Constructor & Destructor Documentation

template<class T>
regina::NFastVector< T >::NFastVector ( unsigned  newVectorSize) [inline]

Creates a new vector.

Its elements will not be initialised.

Parameters:
newVectorSizethe number of elements in the new vector; this must be strictly positive.
template<class T>
regina::NFastVector< T >::NFastVector ( unsigned  newVectorSize,
const T &  initValue 
) [inline]

Creates a new vector and initialises every element to the given value.

Parameters:
newVectorSizethe number of elements in the new vector; this must be strictly positive.
initValuethe value to assign to every element of the vector.
template<class T>
regina::NFastVector< T >::NFastVector ( const NFastVector< T > &  cloneMe) [inline]

Creates a new vector that is a clone of the given vector.

Parameters:
cloneMethe vector to clone.
template<class T>
regina::NFastVector< T >::NFastVector ( const NVector< T > &  cloneMe) [inline]

Creates a new vector that is a clone of the given NVector.

Parameters:
cloneMethe vector to clone.
template<class T>
regina::NFastVector< T >::~NFastVector ( ) [inline]

Destroys this vector.


Member Function Documentation

template<class T>
void regina::NFastVector< T >::addCopies ( const NFastVector< T > &  other,
const T &  multiple 
) [inline]

Adds the given multiple of the given vector to this vector.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector a multiple of which will be added to this vector.
multiplethe multiple of other to be added to this vector.
template<class T>
T regina::NFastVector< T >::elementSum ( ) const [inline]

Returns the sum of all elements of this vector.

Returns:
the sum of the elements of this vector.
template<class T>
void regina::NFastVector< T >::negate ( ) [inline]

Negates every element of this vector.

template<class T>
T regina::NFastVector< T >::norm ( ) const [inline]

Returns the norm of this vector.

This is the dot product of the vector with itself.

Returns:
the norm of this vector.
template<class T>
T regina::NFastVector< T >::operator* ( const NFastVector< T > &  other) const [inline]

Calculates the dot product of this vector and the given vector.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector with which this will be multiplied.
Returns:
the dot product of this and the given vector.
template<class T>
void regina::NFastVector< T >::operator*= ( const T &  factor) [inline]

Multiplies this vector by the given scalar.

Parameters:
factorthe scalar with which this will be multiplied.
template<class T>
void regina::NFastVector< T >::operator+= ( const NFastVector< T > &  other) [inline]

Adds the given vector to this vector.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector to add to this vector.
template<class T>
void regina::NFastVector< T >::operator-= ( const NFastVector< T > &  other) [inline]

Subtracts the given vector from this vector.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector to subtract from this vector.
template<class T>
void regina::NFastVector< T >::operator= ( const NFastVector< T > &  cloneMe) [inline]

Sets this vector equal to the given vector.

Precondition:
This and the given vector have the same size.
Parameters:
cloneMethe vector whose value shall be assigned to this vector.
template<class T>
bool regina::NFastVector< T >::operator== ( const NFastVector< T > &  compare) const [inline]

Determines if this vector is equal to the given vector.

Precondition:
This and the given vector have the same size.
Parameters:
comparethe vector with which this will be compared.
Returns:
true if and only if the this and the given vector are equal.
template<class T>
const T& regina::NFastVector< T >::operator[] ( unsigned  index) const [inline]

Returns the element at the given index in the vector.

A constant reference to the element is returned; the element may not be altered.

Precondition:
index is between 0 and size()-1 inclusive.
Parameters:
indexthe vector index to examine.
Returns:
the vector element at the given index.
template<class T>
void regina::NFastVector< T >::setElement ( unsigned  index,
const T &  value 
) [inline]

Sets the element at the given index in the vector to the given value.

Precondition:
index is between 0 and size()-1 inclusive.
Parameters:
indexthe vector index to examine.
valuethe new value to assign to the element.
Returns:
the vector element at the given index.
template<class T>
unsigned regina::NFastVector< T >::size ( ) const [inline]

Returns the number of elements in the vector.

Returns:
the vector size.
template<class T>
void regina::NFastVector< T >::subtractCopies ( const NFastVector< T > &  other,
const T &  multiple 
) [inline]

Subtracts the given multiple of the given vector to this vector.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector a multiple of which will be subtracted from this vector.
multiplethe multiple of other to be subtracted from this vector.

Member Data Documentation

template<class T>
T* regina::NFastVector< T >::elements [protected]

The internal array containing all vector elements.

template<class T>
T* regina::NFastVector< T >::end [protected]

A pointer just beyond the end of the internal array.

The size of the vector can be computed as (end - elements).


The documentation for this class was generated from the following file:

Copyright © 1999-2009, Ben Burton
This software is released under the GNU General Public License.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).