#include <tnt_array1d.h>
Public Types | |
typedef T | value_type |
Public Methods | |
Array1D () | |
Array1D (int n) | |
Array1D (int n, const T &a) | |
Array1D (int n, T *a) | |
Array1D (const Array1D &A) | |
operator T * () | |
operator const T * () | |
Array1D& | operator= (const T &a) |
Array1D& | operator= (const Array1D &A) |
Array1D& | ref (const Array1D &A) |
Array1D | copy () const |
Array1D& | inject (const Array1D &A) |
T& | operator[] (int i) |
const T& | operator[] (int i) const |
int | dim1 () const |
int | dim () const |
~Array1D () |
Array assignment is by reference (i.e. shallow assignment). That is, B=A implies that the A and B point to the same array, so modifications to the elements of A will be reflected in B. If an independent copy is required, then B = A.copy() can be used. Note that this facilitates returning arrays from functions without relying on compiler optimizations to eliminate extensive data copying.
The indexing and layout of this array object makes it compatible with C and C++ algorithms that utilize the familiar C[i] notation. This includes numerous textbooks, such as Numercial Recipes, and various public domain codes.
|
|
|
Null constructor. Creates a 0-length (NULL) array. (Reference count is also zero.) |
|
Create a new array (vector) of length n, WIHOUT initializing array elements. To create an initialized array of constants, see Array1D(n,value).
This version avoids the O(n) initialization overhead and is used just before manual assignment.
|
|
Create a new array of length n, initializing array elements to constant specified by argument. Most often used to create an array of zeros, as in A(n, 0.0).
|
|
Create an n-length array, as a view of an existing one-dimensional C array. (Note that the storage for this pre-existing array will never be destroyed by the Aray1DRef class.)
|
|
Copy constructor. Array data is NOT copied, but shared. Thus, in Array1D B(A), subsequent changes to A will be reflected in B. For an indepent copy of A, use Array1D B(A.copy()), or B = A.copy(), instead. |
|
Destructor: reclaims all memory possible associated with this array. |
|
Create a new of existing matrix. Used in B = A.copy() or in the construction of B, e.g. Array1D B(A.copy()), to create a new array that does not share data. |
|
|
|
|
|
Copy the elements to from one array to another, in place. That is B.inject(A), both A and B must conform (i.e. have identical row and column dimensions). This differs from B = A.copy() in that references to B before this assignment are also affected. That is, if we have Array1D A(n); Array1D C(n); Array1D B(C); // elements of B and C are shared.then B.inject(A) affects both and C, while B=A.copy() creates a new array B which shares no data with C or A.
|
|
Automatic conversion to a one-dimensional pointer. Useful for integrating with numerical codes that utilize pointer interface interface. Thus, if a function declared as void row_max(double *D);is called with an Array1D<double>, as in Array2D<double> A(N); f(A);then A is automatically converted. Likewise, double *d = A;also converts A into a regular C pointer. |
|
Automatic conversion to a const one-dimensional pointer. Useful for integrating with numerical codes that utilize pointer interface interface. Thus, if a function declared as void row_max(const double *D);is called with an Array1D<double>, as in Array1D<double> A(N); f(A);then A is automatically converted. Likewise, const double *d = A;also converts A into a regular C pointer. |
|
B = A is shorthand notation for B.ref(A). |
|
Assign all elemnts of A to a constant scalar. |
|
A[i] indexes the ith element of A. The first element is A[0]. If TNT_BOUNDS_CHECK is defined, then the index is checked that it fall within the array bounds. |
|
A[i] indexes the ith element of A. The first element is A[0]. If TNT_BOUNDS_CHECK is defined, then the index is checked that it falls within the array bounds. |
|
Create a reference (shallow assignment) to another existing array. In B.ref(A), B and A shared the same data and subsequent changes to the array elements of one will be reflected in the other. This is what operator= calls, and B=A and B.ref(A) are equivalent operations.
|