Vector of vectors. More...
#include <Vector2.hxx>
Public Types | |
typedef T | value_type |
typedef T * | pointer |
typedef T & | reference |
Public Member Functions | |
Vector2 () | |
Default constructor. More... | |
Vector2 (long length) | |
Constructor. More... | |
Vector2 (const Vector< long > &length) | |
Constructor. More... | |
~Vector2 () | |
Destructor. The vector of vectors and the inner vectors are deallocated. | |
bool | IsEmpty () const |
Checks whether no elements are contained in the inner vectors. More... | |
long | GetLength () const |
Returns the size along dimension 1. More... | |
long | GetSize () const |
Returns the size along dimension 1. More... | |
long | GetLength (long i) const |
Returns the size of the inner vector #i. More... | |
long | GetSize (long i) const |
Returns the size of the inner vector #i. More... | |
size_t | GetMemorySize () const |
Returns the memory used by the object in bytes. More... | |
long | GetNelement () const |
Returns the total number of elements in the inner vectors. More... | |
long | GetNelement (long beg, long end) const |
Returns the total number of elements in a range of inner vectors. More... | |
Vector< long > | GetShape () const |
Returns the shape. More... | |
void | GetShape (Vector< long > &shape) const |
Returns the shape. More... | |
void | Reallocate (long M) |
Reallocates the vector of vector. More... | |
void | Reallocate (long i, long N) |
Reallocates the inner vector #i. More... | |
void | Reallocate (const Vector< long > &length) |
Reallocates the whole structure. More... | |
void | Select (long beg, long end) |
Selects a range of inner vectors. More... | |
Vector< T, VectFull, Allocator0 > | Flatten () const |
Returns all values in a vector. More... | |
template<class Td , class Allocatord > | |
void | Flatten (Vector< Td, VectFull, Allocatord > &data) const |
Returns all values in a vector. More... | |
template<class Td , class Allocatord > | |
void | Flatten (long beg, long end, Vector< Td, VectFull, Allocatord > &data) const |
Returns in a vector all values from a range of inner vectors. More... | |
void | PushBack (long i, const T &x) |
Appends an element at the end of the inner vector #i. More... | |
void | PushBack (const Vector< T, VectFull, Allocator0 > &X) |
Appends an inner vector at the end of the vector. More... | |
void | PushBack (const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > &V) |
Appends a vector of vectors. More... | |
void | PushBack (const Vector2< T, Allocator0, Allocator1 > &V) |
Appends a vector of vectors. More... | |
void | Clear () |
Clears the vector. | |
void | Clear (long i) |
Clears a given vector. More... | |
void | Fill (const T &x) |
Fills the vector with a given value. More... | |
Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > & | GetVector () |
Returns the vector of vectors. More... | |
const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > | GetVector () const |
Vector< T, VectFull, Allocator0 > & | GetVector (long i) |
Returns a given inner vector. More... | |
const Vector< T, VectFull, Allocator0 > & | GetVector (long i) const |
Returns a given inner vector. More... | |
void | Copy (const Vector2< T, Allocator0, Allocator1 > &V) |
Copies a Vector2 instance. More... | |
Vector2< T, Allocator0, Allocator1 > | Copy () const |
Copies a Vector2 instance. More... | |
const Vector< T, VectFull, Allocator0 > & | operator() (long i) const |
Returns a given inner vector. More... | |
Vector< T, VectFull, Allocator0 > & | operator() (long i) |
Returns a given inner vector. More... | |
const_reference | operator() (long i, long j) const |
Returns an element of a given inner vector. More... | |
reference | operator() (long i, long j) |
Returns an element of a given inner vector. More... | |
template<class V2 > | |
bool | HasSameShape (const V2 &V) const |
Checks whether another Vector2 instance has the same shape. More... | |
void | Print () const |
Displays the vector. | |
void | Write (string file_name, bool with_size=true) const |
Writes the instance in a binary file. More... | |
void | Write (ostream &file_stream, bool with_size=true) const |
Writes the instance in a stream in a binary format. More... | |
void | Read (string file_name, bool with_size=true) |
Reads the Vector2 from a file. More... | |
void | Read (istream &file_stream, bool with_size=true) |
Reads the Vector2 from a file. More... | |
Public Attributes | |
const typedef T * | const_pointer |
const typedef T & | const_reference |
Protected Attributes | |
Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > | data_ |
Vector of vectors.
Vector2 is a structure that acts like a vector of vectors. The inner vectors can be of any dimension, so that this structure is more flexible than a matrix.
T | numerical type of the inner vectors. |
Allocator0 | allocator for the inner vectors. The default allocator is SELDON_DEFAULT_ALLOCATOR. |
Allocator1 | allocator for the vector of vectors. It is recommended to choose NewAlloc or, for more efficient in reallocations, MallocObject (default allocator here): these allocators can manage an array of inner vectors. |
Definition at line 53 of file Vector2.hxx.
Seldon::Vector2< T, Allocator0, Allocator1 >::Vector2 |
Seldon::Vector2< T, Allocator0, Allocator1 >::Vector2 | ( | long | length | ) |
Constructor.
The vector of vectors is allocated with length empty vectors.
[in] | length | the length of the vector of vectors. |
Definition at line 57 of file Vector2.cxx.
Seldon::Vector2< T, Allocator0, Allocator1 >::Vector2 | ( | const Vector< long > & | length | ) |
Constructor.
The vector of vectors and the inner vectors are allocated.
[in] | length | the lengths of the inner vectors. The vector of vectors will obviously have as many elements as length has. |
Definition at line 69 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Clear | ( | long | i | ) |
Clears a given vector.
[in] | i | index of the vector to be cleared. |
Definition at line 443 of file Vector2.cxx.
Vector2< T, Allocator0, Allocator1 > Seldon::Vector2< T, Allocator0, Allocator1 >::Copy |
Copies a Vector2 instance.
Definition at line 535 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Copy | ( | const Vector2< T, Allocator0, Allocator1 > & | V | ) |
Copies a Vector2 instance.
[in] | V | Vector2 instance to be copied. |
Definition at line 519 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Fill | ( | const T & | x | ) |
Fills the vector with a given value.
[in] | x | value to fill the vector with. |
Definition at line 454 of file Vector2.cxx.
Vector< T, VectFull, Allocator0 > Seldon::Vector2< T, Allocator0, Allocator1 >::Flatten |
Returns all values in a vector.
The output vector contains all inner vectors concatenated in the same order as they appear in the current Vector2 instance.
Definition at line 316 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Flatten | ( | long | beg, |
long | end, | ||
Vector< Td, VectFull, Allocatord > & | data | ||
) | const |
Returns in a vector all values from a range of inner vectors.
The output vector data contains all inner vectors, in the index range [beg, end[, concatenated in the same order as they appear in the current Vector2 instance.
[in] | beg | inclusive lower-bound for the indexes. |
[in] | end | exclusive upper-bound for the indexes. |
[out] | data | the values contained in the inner vectors [beg, end[. |
Definition at line 357 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Flatten | ( | Vector< Td, VectFull, Allocatord > & | data | ) | const |
Returns all values in a vector.
The output vector data contains all inner vectors concatenated in the same order as they appear in the current Vector2 instance.
[out] | data | all values from the current Vector2 instance. |
Definition at line 335 of file Vector2.cxx.
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetLength |
Returns the size along dimension 1.
Definition at line 126 of file Vector2.cxx.
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetLength | ( | long | i | ) | const |
Returns the size of the inner vector #i.
[in] | i | index. |
Definition at line 166 of file Vector2.cxx.
size_t Seldon::Vector2< T, Allocator0, Allocator1 >::GetMemorySize |
Returns the memory used by the object in bytes.
In this method, the type T is assumed to be "static" such that sizeof(T) provides the correct size
Definition at line 150 of file Vector2.cxx.
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetNelement |
Returns the total number of elements in the inner vectors.
Definition at line 177 of file Vector2.cxx.
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetNelement | ( | long | beg, |
long | end | ||
) | const |
Returns the total number of elements in a range of inner vectors.
Returns the total number of elements in the range [beg, end[ of inner vectors.
[in] | beg | inclusive lower-bound for the indexes. |
[in] | end | exclusive upper-bound for the indexes. |
Definition at line 195 of file Vector2.cxx.
Vector< long > Seldon::Vector2< T, Allocator0, Allocator1 >::GetShape |
Returns the shape.
Definition at line 220 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::GetShape | ( | Vector< long > & | shape | ) | const |
Returns the shape.
[out] | shape | the lengths of the inner vectors. |
Definition at line 234 of file Vector2.cxx.
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetSize |
Returns the size along dimension 1.
Definition at line 115 of file Vector2.cxx.
long Seldon::Vector2< T, Allocator0, Allocator1 >::GetSize | ( | long | i | ) | const |
Returns the size of the inner vector #i.
[in] | i | index. |
Definition at line 138 of file Vector2.cxx.
const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > Seldon::Vector2< T, Allocator0, Allocator1 >::GetVector |
Returns the vector of vectors.
Definition at line 467 of file Vector2.cxx.
Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::GetVector | ( | long | i | ) |
Returns a given inner vector.
[in] | i | index of the inner vector. |
Definition at line 492 of file Vector2.cxx.
const Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::GetVector | ( | long | i | ) | const |
Returns a given inner vector.
[in] | i | index of the inner vector. |
Definition at line 505 of file Vector2.cxx.
bool Seldon::Vector2< T, Allocator0, Allocator1 >::HasSameShape | ( | const V2 & | V | ) | const |
Checks whether another Vector2 instance has the same shape.
Checks whether another Vector2 instance has the same shape as the current instance. The shapes are the same if both instances have the same number of inner vectors, and if the inner vectors have the same lengths.
[in] | V | Vector2 instance whose shape is compared to that of the current instance. |
Definition at line 618 of file Vector2.cxx.
bool Seldon::Vector2< T, Allocator0, Allocator1 >::IsEmpty |
Checks whether no elements are contained in the inner vectors.
Definition at line 101 of file Vector2.cxx.
Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::operator() | ( | long | i | ) |
Returns a given inner vector.
[in] | i | index of the inner vector. |
Definition at line 568 of file Vector2.cxx.
const Vector< T, VectFull, Allocator0 > & Seldon::Vector2< T, Allocator0, Allocator1 >::operator() | ( | long | i | ) | const |
Returns a given inner vector.
[in] | i | index of the inner vector. |
Definition at line 555 of file Vector2.cxx.
Vector2< T, Allocator0, Allocator1 >::reference Seldon::Vector2< T, Allocator0, Allocator1 >::operator() | ( | long | i, |
long | j | ||
) |
Returns an element of a given inner vector.
[in] | i | index of the inner vector. |
[in] | j | index of the element in the inner vector #i. |
Definition at line 596 of file Vector2.cxx.
Vector2< T, Allocator0, Allocator1 >::const_reference Seldon::Vector2< T, Allocator0, Allocator1 >::operator() | ( | long | i, |
long | j | ||
) | const |
Returns an element of a given inner vector.
[in] | i | index of the inner vector. |
[in] | j | index of the element in the inner vector #i. |
Definition at line 582 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack | ( | const Vector2< T, Allocator0, Allocator1 > & | V | ) |
Appends a vector of vectors.
The inner vectors of V are appended to the current instance, in the same order as they appear in V.
[in] | V | vector of vectors to be appended. |
Definition at line 424 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack | ( | const Vector< T, VectFull, Allocator0 > & | X | ) |
Appends an inner vector at the end of the vector.
[in] | X | vector to be appended. |
Definition at line 396 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack | ( | const Vector< Vector< T, VectFull, Allocator0 >, VectFull, Allocator1 > & | V | ) |
Appends a vector of vectors.
The inner vectors of V are appended to the current instance, in the same order as they appear in V.
[in] | V | vector of vectors to be appended. |
Definition at line 409 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::PushBack | ( | long | i, |
const T & | x | ||
) |
Appends an element at the end of the inner vector #i.
[in] | i | index of the inner vector to which x should be appended. |
[in] | x | element to be appended. |
Definition at line 384 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Read | ( | istream & | stream, |
bool | with_size = true |
||
) |
Reads the Vector2 from a file.
Sets the current Vector2 instance according to a binary stream that stores the total number of inner vectors, and, for each inner vector, the length of the vector (integer) and its elements.
[in,out] | stream | input stream. |
[in] | with_size | if set to 'false', the total number of inner vectors and the lengths of the vectors are not available in the stream. In this case, the shape of the current instance is unchanged and the values of the elements are directly read in the file. |
Definition at line 760 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Read | ( | string | file_name, |
bool | with_size = true |
||
) |
Reads the Vector2 from a file.
Sets the current Vector2 instance according to a binary file that stores the total number of inner vectors, and, for each inner vector, the length of the vector (integer) and its elements.
[in] | file_name | file name. |
[in] | with_size | if set to 'false', the total number of inner vectors and the lengths of the vectors are not available in the file. In this case, the shape of the current instance is unchanged and the values of the elements are directly read in the file. |
Definition at line 729 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Reallocate | ( | const Vector< long > & | length | ) |
Reallocates the whole structure.
[in] | length | the new lengths of the inner vectors. The vector of vectors will obviously have as many elements as length has. |
Definition at line 272 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Reallocate | ( | long | i, |
long | N | ||
) |
Reallocates the inner vector #i.
[in] | i | index of the inner vector to be reallocated. |
[in] | N | the new size of the inner vector #i. |
Definition at line 259 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Reallocate | ( | long | M | ) |
Reallocates the vector of vector.
[in] | M | the new size of the vector of vectors. |
Definition at line 247 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Select | ( | long | beg, |
long | end | ||
) |
Selects a range of inner vectors.
Only the inner vectors with index in [beg, end[ are kept. The other vectors are destroyed.
[in] | beg | inclusive lower-bound for the indexes. |
[in] | end | exclusive upper-bound for the indexes. |
Definition at line 288 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Write | ( | ostream & | stream, |
bool | with_size = true |
||
) | const |
Writes the instance in a stream in a binary format.
The number of inner vectors (longeger) is written first. Then for each vector, the length of the vector (longeger) and all elements of the vector are written.
[in,out] | stream | output stream. |
[in] | with_size | if set to 'false', the number of vectors and the lengths of the inner vectors are not saved. |
Definition at line 686 of file Vector2.cxx.
void Seldon::Vector2< T, Allocator0, Allocator1 >::Write | ( | string | file_name, |
bool | with_size = true |
||
) | const |
Writes the instance in a binary file.
The number of inner vectors (longeger) is written first. Then for each vector, the length of the vector (longeger) and all elements of the vector are written.
[in] | file_name | file name. |
[in] | with_size | if set to 'false', the number of vectors and the lengths of the inner vectors are not saved. |
Definition at line 657 of file Vector2.cxx.