Jet
v1.3.3
|
2-D array class. More...
#include <jet/array2.h>
Public Types | |
typedef std::vector< T > | ContainerType |
typedef ContainerType::iterator | Iterator |
typedef ContainerType::const_iterator | ConstIterator |
Public Member Functions | |
Array () | |
Constructs zero-sized 2-D array. More... | |
Array (const Size2 &size, const T &initVal=T()) | |
Array (size_t width, size_t height, const T &initVal=T()) | |
Array (const std::initializer_list< std::initializer_list< T >> &lst) | |
Constructs 2-D array with given initializer list lst . More... | |
Array (const Array &other) | |
Copy constructor. More... | |
Array (Array &&other) | |
Move constructor. More... | |
void | set (const T &value) |
Sets entire array with given value . More... | |
void | set (const Array &other) |
Copies given array other to this array. More... | |
void | set (const std::initializer_list< std::initializer_list< T >> &lst) |
void | clear () |
Clears the array and resizes to zero. More... | |
void | resize (const Size2 &size, const T &initVal=T()) |
Resizes the array with size and fill the new element with initVal . More... | |
void | resize (size_t width, size_t height, const T &initVal=T()) |
T & | at (size_t i) |
Returns the reference to the i-th element. More... | |
const T & | at (size_t i) const |
Returns the const reference to the i-th element. More... | |
T & | at (const Point2UI &pt) |
Returns the reference to the element at (pt.x, pt.y). More... | |
const T & | at (const Point2UI &pt) const |
Returns the const reference to the element at (pt.x, pt.y). More... | |
T & | at (size_t i, size_t j) |
Returns the reference to the element at (i, j). More... | |
const T & | at (size_t i, size_t j) const |
Returns the const reference to the element at (i, j). More... | |
Size2 | size () const |
Returns the size of the array. More... | |
size_t | width () const |
Returns the width of the array. More... | |
size_t | height () const |
Returns the height of the array. More... | |
T * | data () |
Returns the raw pointer to the array data. More... | |
const T *const | data () const |
Returns the const raw pointer to the array data. More... | |
Iterator | begin () |
Returns the begin iterator of the array. More... | |
ConstIterator | begin () const |
Returns the begin const iterator of the array. More... | |
Iterator | end () |
Returns the end iterator of the array. More... | |
ConstIterator | end () const |
Returns the end const iterator of the array. More... | |
ArrayAccessor2< T > | accessor () |
Returns the array accessor. More... | |
ConstArrayAccessor2< T > | constAccessor () const |
Returns the const array accessor. More... | |
void | swap (Array &other) |
Swaps the content of the array with other array. More... | |
template<typename Callback > | |
void | forEach (Callback func) const |
Iterates the array and invoke given func for each index. More... | |
template<typename Callback > | |
void | forEachIndex (Callback func) const |
Iterates the array and invoke given func for each index. More... | |
template<typename Callback > | |
void | parallelForEach (Callback func) |
Iterates the array and invoke given func for each index in parallel. More... | |
template<typename Callback > | |
void | parallelForEachIndex (Callback func) const |
Iterates the array and invoke given func for each index in parallel using multi-threading. More... | |
T & | operator[] (size_t i) |
Returns the reference to the i-th element. More... | |
const T & | operator[] (size_t i) const |
Returns the const reference to the i-th element. More... | |
T & | operator() (const Point2UI &pt) |
Returns the reference to the element at (pt.x, pt.y). More... | |
const T & | operator() (const Point2UI &pt) const |
Returns the const reference to the element at (pt.x, pt.y). More... | |
T & | operator() (size_t i, size_t j) |
Returns the reference to the element at (i, j). More... | |
const T & | operator() (size_t i, size_t j) const |
Returns the const reference to the element at (i, j). More... | |
Array & | operator= (const T &other) |
Sets entire array with given value . More... | |
Array & | operator= (const Array &other) |
Copies given array other to this array. More... | |
Array & | operator= (Array &&other) |
Move assignment. More... | |
Array & | operator= (const std::initializer_list< std::initializer_list< T >> &lst) |
operator ArrayAccessor2< T > () | |
Casts to array accessor. More... | |
operator ConstArrayAccessor2< T > () const | |
Casts to const array accessor. More... | |
2-D array class.
This class represents 2-D array data structure. Internally, the 2-D data is mapped to a linear array such that (i, j) element is actually stroed at (i + (width * j))th element of the linear array. This mapping means iterating i first and j next will give better performance such as:
T | - Type to store in the array. |
typedef ContainerType::const_iterator jet::Array< T, 2 >::ConstIterator |
typedef std::vector<T> jet::Array< T, 2 >::ContainerType |
typedef ContainerType::iterator jet::Array< T, 2 >::Iterator |
jet::Array< T, 2 >::Array | ( | ) |
Constructs zero-sized 2-D array.
|
explicit |
Constructs 2-D array with given size
and fill it with initVal
.
size | Initial size of the array. |
initVal | Initial value of each array element. |
jet::Array< T, 2 >::Array | ( | size_t | width, |
size_t | height, | ||
const T & | initVal = T() |
||
) |
Constructs 2-D array with size width
x height
and fill it with initVal
.
width | Initial width of the array. |
height | Initial height of the array. |
initVal | Initial value of each array element. |
jet::Array< T, 2 >::Array | ( | const std::initializer_list< std::initializer_list< T >> & | lst | ) |
Constructs 2-D array with given initializer list lst
.
This constructor will build 2-D array with given initializer list lst
such as
Note the initializer also has 2-D structure. The code above will construct 3 x 2 array.
lst | Initializer list that should be copy to the new array. |
jet::Array< T, 2 >::Array | ( | const Array< T, 2 > & | other | ) |
Copy constructor.
jet::Array< T, 2 >::Array | ( | Array< T, 2 > && | other | ) |
Move constructor.
ArrayAccessor2<T> jet::Array< T, 2 >::accessor | ( | ) |
Returns the array accessor.
T& jet::Array< T, 2 >::at | ( | const Point2UI & | pt | ) |
Returns the reference to the element at (pt.x, pt.y).
const T& jet::Array< T, 2 >::at | ( | const Point2UI & | pt | ) | const |
Returns the const reference to the element at (pt.x, pt.y).
T& jet::Array< T, 2 >::at | ( | size_t | i | ) |
Returns the reference to the i-th element.
This function returns the reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + (width * y) (x and y are the 2-D coordinates of the element).
const T& jet::Array< T, 2 >::at | ( | size_t | i | ) | const |
Returns the const reference to the i-th element.
This function returns the const reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + (width * y) (x and y are the 2-D coordinates of the element).
T& jet::Array< T, 2 >::at | ( | size_t | i, |
size_t | j | ||
) |
Returns the reference to the element at (i, j).
const T& jet::Array< T, 2 >::at | ( | size_t | i, |
size_t | j | ||
) | const |
Returns the const reference to the element at (i, j).
Iterator jet::Array< T, 2 >::begin | ( | ) |
Returns the begin iterator of the array.
ConstIterator jet::Array< T, 2 >::begin | ( | ) | const |
Returns the begin const iterator of the array.
void jet::Array< T, 2 >::clear | ( | ) |
Clears the array and resizes to zero.
ConstArrayAccessor2<T> jet::Array< T, 2 >::constAccessor | ( | ) | const |
Returns the const array accessor.
T* jet::Array< T, 2 >::data | ( | ) |
Returns the raw pointer to the array data.
const T* const jet::Array< T, 2 >::data | ( | ) | const |
Returns the const raw pointer to the array data.
Iterator jet::Array< T, 2 >::end | ( | ) |
Returns the end iterator of the array.
ConstIterator jet::Array< T, 2 >::end | ( | ) | const |
Returns the end const iterator of the array.
void jet::Array< T, 2 >::forEach | ( | Callback | func | ) | const |
Iterates the array and invoke given func
for each index.
This function iterates the array elements and invoke the callback function func
. The callback function takes array's element as its input. The order of execution will be the same as the nested for-loop below:
Below is the sample usage:
void jet::Array< T, 2 >::forEachIndex | ( | Callback | func | ) | const |
Iterates the array and invoke given func
for each index.
This function iterates the array elements and invoke the callback function func
. The callback function takes two parameters which are the (i, j) indices of the array. The order of execution will be the same as the nested for-loop below:
Below is the sample usage:
size_t jet::Array< T, 2 >::height | ( | ) | const |
Returns the height of the array.
jet::Array< T, 2 >::operator ArrayAccessor2< T > | ( | ) |
Casts to array accessor.
jet::Array< T, 2 >::operator ConstArrayAccessor2< T > | ( | ) | const |
Casts to const array accessor.
T& jet::Array< T, 2 >::operator() | ( | const Point2UI & | pt | ) |
Returns the reference to the element at (pt.x, pt.y).
const T& jet::Array< T, 2 >::operator() | ( | const Point2UI & | pt | ) | const |
Returns the const reference to the element at (pt.x, pt.y).
T& jet::Array< T, 2 >::operator() | ( | size_t | i, |
size_t | j | ||
) |
Returns the reference to the element at (i, j).
const T& jet::Array< T, 2 >::operator() | ( | size_t | i, |
size_t | j | ||
) | const |
Returns the const reference to the element at (i, j).
Array& jet::Array< T, 2 >::operator= | ( | Array< T, 2 > && | other | ) |
Move assignment.
Array& jet::Array< T, 2 >::operator= | ( | const Array< T, 2 > & | other | ) |
Copies given array other
to this array.
Array& jet::Array< T, 2 >::operator= | ( | const std::initializer_list< std::initializer_list< T >> & | lst | ) |
Copies given initializer list lst
to this array.
This function copies given initializer list lst
to the array such as
Note the initializer also has 2-D structure. The code above will build 3 x 2 array.
lst | Initializer list that should be copy to the new array. |
Array& jet::Array< T, 2 >::operator= | ( | const T & | other | ) |
Sets entire array with given value
.
T& jet::Array< T, 2 >::operator[] | ( | size_t | i | ) |
Returns the reference to the i-th element.
This function returns the reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + (width * y) (x and y are the 2-D coordinates of the element).
const T& jet::Array< T, 2 >::operator[] | ( | size_t | i | ) | const |
Returns the const reference to the i-th element.
This function returns the const reference to the i-th element of the array where i is the index of linearly mapped elements such that i = x + (width * y) (x and y are the 2-D coordinates of the element).
void jet::Array< T, 2 >::parallelForEach | ( | Callback | func | ) |
Iterates the array and invoke given func
for each index in parallel.
This function iterates the array elements and invoke the callback function func
. The callback function takes array's element as its input. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
The parameter type of the callback function doesn't have to be T&, but const T& or T can be used as well.
void jet::Array< T, 2 >::parallelForEachIndex | ( | Callback | func | ) | const |
Iterates the array and invoke given func
for each index in parallel using multi-threading.
This function iterates the array elements and invoke the callback function func
in parallel using multi-threading. The callback function takes two parameters which are the (i, j) indices of the array. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
void jet::Array< T, 2 >::resize | ( | const Size2 & | size, |
const T & | initVal = T() |
||
) |
Resizes the array with size
and fill the new element with initVal
.
void jet::Array< T, 2 >::resize | ( | size_t | width, |
size_t | height, | ||
const T & | initVal = T() |
||
) |
Resizes the array with size width
x height
and fill the new element with initVal
.
void jet::Array< T, 2 >::set | ( | const Array< T, 2 > & | other | ) |
Copies given array other
to this array.
void jet::Array< T, 2 >::set | ( | const std::initializer_list< std::initializer_list< T >> & | lst | ) |
Copies given initializer list lst
to this array.
This function copies given initializer list lst
to the array such as
Note the initializer also has 2-D structure. The code above will build 3 x 2 array.
lst | Initializer list that should be copy to the new array. |
void jet::Array< T, 2 >::set | ( | const T & | value | ) |
Sets entire array with given value
.
Size2 jet::Array< T, 2 >::size | ( | ) | const |
Returns the size of the array.
void jet::Array< T, 2 >::swap | ( | Array< T, 2 > & | other | ) |
Swaps the content of the array with other
array.
size_t jet::Array< T, 2 >::width | ( | ) | const |
Returns the width of the array.