Regina 7.0 Calculation Engine
|
An optimised vector class of elements from a given ring T. More...
#include <maths/vector.h>
Public Types | |
using | value_type = T |
The type of element that is stored in this vector. More... | |
using | size_type = size_t |
The type used for indexing into this vector. More... | |
using | reference = T & |
A reference to an element of this vector. More... | |
using | const_reference = const T & |
A const reference to an element of this vector. More... | |
using | iterator = T * |
The non-const iterator type for this vector. More... | |
using | const_iterator = const T * |
The const iterator type for this vector. More... | |
using | Element = T |
Deprecated alias for the type of element that is stored in this vector. More... | |
Public Member Functions | |
Vector (size_t newVectorSize) | |
Creates a new vector. More... | |
Vector (size_t newVectorSize, const T &initValue) | |
Creates a new vector and initialises every element to the given value. More... | |
template<typename iterator > | |
Vector (iterator begin, iterator end) | |
Creates a new vector containing the given sequence of elements. More... | |
Vector (std::initializer_list< T > data) | |
Creates a new vector containing the given hard-coded elements. More... | |
Vector (const Vector< T > &src) | |
Creates a new vector that is a clone of the given vector. More... | |
Vector (Vector &&src) noexcept | |
Moves the given vector into this new vector. More... | |
~Vector () | |
Destroys this vector. More... | |
size_t | size () const |
Returns the number of elements in the vector. More... | |
const T & | operator[] (size_t index) const |
Returns the element at the given index in the vector. More... | |
T & | operator[] (size_t index) |
Gives write access to the element at the given index in the vector. More... | |
void | setElement (size_t index, const T &value) |
Deprecated routine that sets the element at the given index in the vector to the given value. More... | |
iterator | begin () |
Returns the beginning of a non-const iterator range that runs through all elements of this vector. More... | |
const_iterator | begin () const |
Returns the beginning of a const iterator range that runs through all elements of this vector. More... | |
iterator | end () |
Returns the end of a non-const iterator range that runs through all elements of this vector. More... | |
const_iterator | end () const |
Returns the end of a const iterator range that runs through all elements of this vector. More... | |
bool | operator== (const Vector< T > &compare) const |
Determines if this vector is equal to the given vector. More... | |
bool | operator!= (const Vector< T > &compare) const |
Determines if this vector is different from the given vector. More... | |
Vector< T > & | operator= (const Vector< T > &src) |
Sets this vector equal to the given vector. More... | |
Vector & | operator= (Vector &&src) noexcept |
Moves the given vector into this vector. More... | |
void | swap (Vector &other) noexcept |
Swaps the contents of this and the given vector. More... | |
Vector & | operator+= (const Vector< T > &other) |
Adds the given vector to this vector. More... | |
Vector & | operator-= (const Vector< T > &other) |
Subtracts the given vector from this vector. More... | |
Vector & | operator*= (const T &factor) |
Multiplies this vector by the given scalar. More... | |
Vector | operator+ (const Vector< T > &other) const |
Adds the given vector to this vector, and returns the result. More... | |
Vector | operator- (const Vector< T > &other) const |
Subtracts the given vector from this vector, and returns the result. More... | |
Vector | operator* (const T &factor) const |
Multiplies this vector by the given scalar, and returns the result. More... | |
T | operator* (const Vector< T > &other) const |
Calculates the dot product of this vector and the given vector. More... | |
void | negate () |
Negates every element of this vector. More... | |
T | norm () const |
Returns the norm of this vector. More... | |
T | elementSum () const |
Returns the sum of all elements of this vector. More... | |
void | addCopies (const Vector< T > &other, const T &multiple) |
Adds the given multiple of the given vector to this vector. More... | |
void | subtractCopies (const Vector< T > &other, const T &multiple) |
Subtracts the given multiple of the given vector to this vector. More... | |
bool | isZero () const |
Determines whether this is the zero vector. More... | |
void | writeTextShort (std::ostream &out) const |
Writes a short text representation of this object to the given output stream. More... | |
void | scaleDown () |
Scales this vector down by the greatest common divisor of all its elements. More... | |
void | writeTextLong (std::ostream &out) const |
A default implementation for detailed output. More... | |
std::string | str () const |
Returns a short text representation of this object. More... | |
std::string | utf8 () const |
Returns a short text representation of this object using unicode characters. More... | |
std::string | detail () const |
Returns a detailed text representation of this object. More... | |
Static Public Member Functions | |
static Vector | unit (size_t dimension, size_t coordinate) |
Returns the given unit vector. More... | |
Static Public Attributes | |
static const T | zero |
Zero in the underlying number system. More... | |
static const T | one |
One in the underlying number system. More... | |
static const T | minusOne |
Negative one in the underlying number system. More... | |
Protected Attributes | |
T * | elts_ |
The internal array containing all vector elements. More... | |
T * | end_ |
A pointer just beyond the end of the internal array. More... | |
An optimised vector class of elements from a given ring T.
Various mathematical vector operations are available.
This class is intended for serious computation, and as a result it has a streamlined implementation with no virtual methods. It can be subclassed, but since there are no virtual methods, type information must generally be known at compile time. Nevertheless, in many respects, different subclasses of Vector<T> can happily interact with one another.
This class is written with bulky types in mind (such as arbitrary precision integers), and so creations and operations are kept to a minimum.
As of Regina 7.0, this class explicitly supports zero-length vectors.
This class implements C++ move semantics and adheres to the C++ Swappable requirement. It is designed to avoid deep copies wherever possible, even when passing or returning objects by value.
a
and b
are of type T, then a
can be initialised to the value of b
using a(b)
. =
, ==
, +=
, -=
, *=
, +
, -
and *
. a
is of type T, then a
can be initialised to an integer l
using a(l)
. t
of type T can be written to an output stream out
using the standard expression out << t
.using regina::Vector< T >::const_iterator = const T* |
The const iterator type for this vector.
using regina::Vector< T >::const_reference = const T& |
A const reference to an element of this vector.
using regina::Vector< T >::Element = T |
Deprecated alias for the type of element that is stored in this vector.
using regina::Vector< T >::iterator = T* |
The non-const iterator type for this vector.
using regina::Vector< T >::reference = T& |
A reference to an element of this vector.
using regina::Vector< T >::size_type = size_t |
The type used for indexing into this vector.
using regina::Vector< T >::value_type = T |
The type of element that is stored in this vector.
|
inline |
Creates a new vector.
All entries will be initialised using their default constructors. In particular, this means that for Regina's own integer classes (Integer, LargeInteger and NativeInteger), all entries will be initialised to zero.
int
or long
), then the elements will not be initialised to any particular value.newVectorSize | the number of elements in the new vector. |
|
inline |
Creates a new vector and initialises every element to the given value.
newVectorSize | the number of elements in the new vector. |
initValue | the value to assign to every element of the vector. |
|
inline |
Creates a new vector containing the given sequence of elements.
This constructor induces a deep copy of the given range.
end - begin
, and so ideally iterator should be a random access iterator type for which this operation is constant time.begin | the beginning of the sequence of elements. |
end | a past-the-end iterator indicating the end of the sequence of elements. |
|
inline |
Creates a new vector containing the given hard-coded elements.
This constructor can be used (for example) to create hard-coded examples directly in C++ code.
data | the elements of the vector. |
|
inline |
Creates a new vector that is a clone of the given vector.
src | the vector to clone. |
|
inlinenoexcept |
Moves the given vector into this new vector.
This is a fast (constant time) operation.
The vector that is passed (src) will no longer be usable.
src | the vector to move. |
|
inline |
Destroys this vector.
|
inline |
Adds the given multiple of the given vector to this vector.
This behaves correctly in the case where other is this
.
other | the vector a multiple of which will be added to this vector. |
multiple | the multiple of other to be added to this vector. |
|
inline |
Returns the beginning of a non-const iterator range that runs through all elements of this vector.
This is safe to use even if this vector has zero length (in which case begin() and end() will be equal).
|
inline |
Returns the beginning of a const iterator range that runs through all elements of this vector.
This is safe to use even if this vector has zero length (in which case begin() and end() will be equal).
|
inherited |
Returns a detailed text representation of this object.
This text may span many lines, and should provide the user with all the information they could want. It should be human-readable, should not contain extremely long lines (which cause problems for users reading the output in a terminal), and should end with a final newline. There are no restrictions on the underlying character set.
|
inline |
Returns the sum of all elements of this vector.
|
inline |
Returns the end of a non-const iterator range that runs through all elements of this vector.
This is safe to use even if this vector has zero length (in which case begin() and end() will be equal).
|
inline |
Returns the end of a const iterator range that runs through all elements of this vector.
This is safe to use even if this vector has zero length (in which case begin() and end() will be equal).
|
inline |
Determines whether this is the zero vector.
true
if and only if all elements of the vector are zero.
|
inline |
Negates every element of this vector.
|
inline |
Returns the norm of this vector.
This is the dot product of the vector with itself.
|
inline |
Determines if this vector is different from the given vector.
It is safe to call this operator if this and the given vector have different sizes (in which case the return value will be true
).
compare | the vector with which this will be compared. |
true
if and only if the this and the given vector are not equal.
|
inline |
Multiplies this vector by the given scalar, and returns the result.
This vector will not be changed.
factor | the scalar to multiply this vector by. |
this * factor
.
|
inline |
Calculates the dot product of this vector and the given vector.
other | the vector with which this will be multiplied. |
|
inline |
Multiplies this vector by the given scalar.
This vector will be changed directly.
factor | the scalar with which this will be multiplied. |
|
inline |
Adds the given vector to this vector, and returns the result.
This vector will not be changed.
other | the vector to add to this vector. |
this + other
.
|
inline |
Adds the given vector to this vector.
This vector will be changed directly. This behaves correctly in the case where other is this
.
other | the vector to add to this vector. |
|
inline |
Subtracts the given vector from this vector, and returns the result.
This vector will not be changed.
other | the vector to subtract from this vector. |
this - other
.
|
inline |
Subtracts the given vector from this vector.
This vector will be changed directly. This behaves correctly in the case where other is this
.
other | the vector to subtract from this vector. |
|
inline |
Sets this vector equal to the given vector.
It does not matter if this and the given vector have different sizes; if they do then this vector will be resized as a result.
src | the vector whose value shall be assigned to this vector. |
|
inlinenoexcept |
Moves the given vector into this vector.
This is a fast (constant time) operation.
It does not matter if this and the given vector have different sizes; if they do then this vector will be resized as a result.
The vector that is passed (src) will no longer be usable.
src | the vector to move. |
|
inline |
Determines if this vector is equal to the given vector.
It is safe to call this operator if this and the given vector have different sizes (in which case the return value will be false
).
compare | the vector with which this will be compared. |
true
if and only if the this and the given vector are equal.
|
inline |
Gives write access to the element at the given index in the vector.
index
is between 0 and size()-1 inclusive.index | the vector index to access. |
|
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.
index
is between 0 and size()-1 inclusive.index | the vector index to examine. |
|
inline |
Scales this vector down by the greatest common divisor of all its elements.
The resulting vector will be the smallest multiple of the original that maintains integral entries, and these entries will have the same signs as the originals.
In particular, if this vector is being used to represent a ray emanating from the origin, then this routine reduces the ray to its smallest possible integer representation.
This routine poses no problem for vectors containing infinite elements; such elements are simply ignored and left at infinity.
This routine is only available when T is one of Regina's own integer classes (Integer, LargeInteger, or NativeInteger).
|
inline |
Deprecated routine that sets the element at the given index in the vector to the given value.
index
is between 0 and size()-1 inclusive.index | the vector index to examine. |
value | the new value to assign to the element. |
|
inline |
Returns the number of elements in the vector.
|
inherited |
Returns a short text representation of this object.
This text should be human-readable, should use plain ASCII characters where possible, and should not contain any newlines.
Within these limits, this short text ouptut should be as information-rich as possible, since in most cases this forms the basis for the Python str()
and repr()
functions.
str()
will use precisely this function, and for most classes the Python repr()
function will incorporate this into its output.
|
inline |
Subtracts the given multiple of the given vector to this vector.
This behaves correctly in the case where other is this
.
other | the vector a multiple of which will be subtracted from this vector. |
multiple | the multiple of other to be subtracted from this vector. |
|
inlinenoexcept |
Swaps the contents of this and the given vector.
other | the vector whose contents are to be swapped with this. |
|
inlinestatic |
Returns the given unit vector.
The vector will have length dimension. The element in position coordinate will be set to 1, and all other elements will be set to 0.
dimension | the number of elements in the vector. |
coordinate | the coordinate position that should hold the value 1; this must be between 0 and (dimension - 1) inclusive. |
|
inherited |
Returns a short text representation of this object using unicode characters.
Like str(), this text should be human-readable, should not contain any newlines, and (within these constraints) should be as information-rich as is reasonable.
Unlike str(), this function may use unicode characters to make the output more pleasant to read. The string that is returned will be encoded in UTF-8.
|
inlineinherited |
A default implementation for detailed output.
This routine simply calls T::writeTextShort() and appends a final newline.
out | the output stream to which to write. |
|
inline |
Writes a short text representation of this object to the given output stream.
out | the output stream to which to write. |
|
protected |
The internal array containing all vector elements.
|
protected |
A pointer just beyond the end of the internal array.
The size of the vector can be computed as (end_ - elts_).
|
static |
Negative one in the underlying number system.
|
static |
One in the underlying number system.
|
static |
Zero in the underlying number system.