Template class for an Array of type T based on a STL vector. More...
#include <array.h>
Public Member Functions | |
template<> | |
string * | printToString () |
Constructors | |
array () | |
Default constructor. | |
array (int32 size) | |
Constructor: allocate size elements. | |
array (T val, int32 size) | |
Constructor: fill size elements with val. | |
array (const array &ar2) | |
Copy constructor. | |
array (const T *ar2, int32 size) | |
constructor with T* array. | |
array (const string &str) | |
string constructor | |
array (const string &str, int32 &pos) | |
string constructor with position in string | |
~array () | |
Destructor. | |
Vector wrapper functions | |
T & | operator[] (int32 idx) |
access element at index idx | |
const T & | operator[] (int32 idx) const |
access element at index idx | |
T & | front () |
access element at index idx | |
const T & | front () const |
access element at index idx | |
T & | back () |
access element at index idx | |
const T & | back () const |
access element at index idx | |
int32 | size () const |
access element at index idx | |
void | insert (int32 idx, int32 len, const T &val) |
access element at index idx | |
void | erase (int32 idx, int32 len) |
access element at index idx | |
Operations on complete array | |
string * | printToString () |
prints the array to string | |
void | print () |
prints the array to stdout | |
string * | toString () |
creates a string containing a copy of the array data | |
void | appendToString (string &str) |
appends a copy of the array data to a string | |
template<class T2 > | |
array< T2 > * | convertTo () |
convert into array of different type | |
Array copy & paste, etc. | |
array< T > * | copy () |
return a copy of the array | |
void | put (const array &ar2) |
Put new data in current array. | |
void | put (const array &ar2, int32 idx) |
void | put (const array &ar2, int32 idx, int32 len) |
void | put (T val, int32 idx) |
Put a single value in current array. | |
void | fill (T val) |
Fill the array with a single value. | |
void | fill (T val, int32 idx) |
Fill part of the array with a single value. | |
void | fill (T val, int32 idx, int32 len) |
void | replace (const array &ar2) |
Replace this array by new data. | |
void | replace (const array &ar2, int32 idx) |
Replace part of a array by new data. | |
void | replace (const array &ar2, int32 idx, int32 len) |
void | replaceFill (T val, int32 num) |
Replace the array by num values. | |
void | replaceFill (T val, int32 num, int32 idx) |
Replace part of the array by num values. | |
void | replaceFill (T val, int32 num, int32 idx, int32 len) |
void | selectFill (T val, array< int32 > &idxs) |
fill elements indexed by idxs array with val | |
template<class T2 > | |
void | selectPut (const array< T2 > &ar2, array< int32 > &idxs) |
fill elements indexed by idxs array with elements from ar2 | |
array< T > * | selectGet (array< int32 > &idxs) |
get values of current array indexed by idxs | |
void | del (int32 idx, int32 len) |
return a copy of the array | |
void | crop (int32 idx, int32 len) |
return a copy of the array | |
Array inspection | |
int32 | find (T val) |
Find position of a specific value. | |
int32 | find (T val, int32 idx) |
int32 | findNe (T val) |
Find position of a value not equal to the specific value. | |
int32 | findNe (T val, int32 idx) |
T | at (int32 idx) |
Return element at specified position. | |
T | max () |
maximum value of the array | |
T | min () |
minimum value of the array | |
array< int32 > * | which () |
returns indices of non-zero elements | |
array< int32 > * | whichEq (T val) |
returns indices of elements equal to val | |
array< int32 > * | whichLt (T val) |
returns indices of elements less than val | |
array< int32 > * | whichLe (T val) |
returns indices of elements less than or equal to val | |
array< int32 > * | whichGt (T val) |
returns indices of elements greater than val | |
array< int32 > * | whichGe (T val) |
returns indices of elements greater than or equal to val | |
component wise operations | |
int32 | nz () |
number of non-zero elements | |
void | scale (T mult) |
multiply all components by mult | |
template<class T2 > | |
void | add (array< T2 > &ar2) |
add second array component by component | |
template<class T2 > | |
void | add (array< T2 > &ar2, T mult) |
add second array multiplied by mult component by component | |
template<class T2 > | |
void | sub (array< T2 > &ar2) |
subtract second array component by component | |
template<class T2 > | |
bool | isSubsetOf (array< T2 > &ar2) |
true if current array has zeros wherever ar2 has zeroes | |
template<class T2 > | |
bool | isSetEq (array< T2 > &ar2) |
combine arrays using AND operator | |
template<class T2 > | |
void | AND (array< T2 > &ar2) |
combine arrays using AND operator | |
template<class T2 > | |
int32 | ANDnz (array< T2 > &ar2) |
size of cutset | |
template<class T2 > | |
void | OR (array< T2 > &ar2) |
combine arrays using OR operator | |
template<class T2 > | |
int32 | ORnz (array< T2 > &ar2) |
size of set union | |
template<class T2 > | |
void | subSet (array< T2 > &ar2) |
substract(boolean) ar2 from current array | |
template<class T2 > | |
int32 | subSetnz (array< T2 > &ar2) |
size of set substraction (substract(boolean) ar2 from current array) | |
Protected Member Functions | |
void | _set (const array &ar2, int32 idx, int32 len) |
internal method copying data from a different array to the current array | |
void | _fill (T val, int32 idx, int32 len) |
internal method writing single values in the array | |
void | _arrange (int32 idx, int32 &len, int32 srclen, bool repl) |
internal method reserving the place in the current array |
Template class for an Array of type T based on a STL vector.
Provides routines for manipulating the vector, inlcuding arithmetical (i.e. adding) and logical (i.e. AND, OR) and set operations. Contains routines to insert and overwrite data without using iterators.
Constructor: fill size elements with val.
constructor with T* array.
string constructor with position in string
void array< T >::_arrange | ( | int32 | idx, | |
int32 & | len, | |||
int32 | srclen, | |||
bool | repl | |||
) | [inline, protected] |
internal method reserving the place in the current array
idx | index at which new data should be placed | |
len | length of the part in current array that should be replaced (by reference - may be changed) | |
srclen | length of the new data | |
repl | true if the new data should replace the old part or false if this should overwrite |
Note: len is always set to srclen, indicating that in the arranged array len=srclen elements are to be written
internal method writing single values in the array
val | value with which part of the array should be filled | |
idx | index at which new data should be placed | |
len | length of the part in current array that should be filled |
Fills len elements with val from index idx on. The length of the current array should already be arranged acordingly.
void array< T >::_set | ( | const array< T > & | ar2, | |
int32 | idx, | |||
int32 | len | |||
) | [inline, protected] |
internal method copying data from a different array to the current array
ar2 | array containing the data to read from | |
idx | index at which the copied data should be placed | |
len | length of the part in current array that should be filled |
Fills len elements with data from ar2 from position idx in the current array. The length of the current array should already be arranged accordingly.
add second array multiplied by mult component by component
add second array component by component
combine arrays using AND operator
size of cutset
void array< T >::appendToString | ( | string & | str | ) | [inline] |
appends a copy of the array data to a string
Return element at specified position.
idx | index of queried element |
returns reference to original element
const T & array< T >::back | ( | ) | const [inline] |
access element at index idx
idx | element index to access |
T & array< T >::back | ( | ) | [inline] |
access element at index idx
idx | element index to access |
convert into array of different type
return a copy of the array
return a copy of the array
access element at index idx
idx | element index to access |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
val | value with which part of the array should be filled | |
idx | index at which ar2 should be placed | |
len | length of the part which should be replaced |
Everything from idx to idx+len of the array is filled with val. The length of the array is changed if idx+len is larger than the current len.
Fill part of the array with a single value.
val | value with which part of the array should be filled | |
idx | index at which ar2 should be placed |
Everything from idx to the end of the array is filled with val.
void array< T >::fill | ( | T | val | ) | [inline] |
Fill the array with a single value.
val | value with which part of the array should be filled | |
idx | index at which ar2 should be placed |
Everything from the beginning to the end of the array is filled with val.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
val | value to be looked for |
Returns the index of the first element after or at position idx with value val in the array. Returns -1 of val is not found.
Find position of a specific value.
val | value to be looked for |
Returns the index of the first element with value val in the array. Returns -1 of val is not found.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
val | value to be looked for |
Returns the index of the first element after or at position idx whose value is not val in the array. Returns -1 of value!=val is not found.
Find position of a value not equal to the specific value.
val | value to be looked for |
Returns the index of the first element whose value is not val in the array. Returns -1 of value!=val is not found.
const T & array< T >::front | ( | ) | const [inline] |
access element at index idx
idx | element index to access |
T & array< T >::front | ( | ) | [inline] |
access element at index idx
idx | element index to access |
access element at index idx
idx | element index to access |
combine arrays using AND operator
true if current array has zeros wherever ar2 has zeroes
T array< T >::max | ( | ) | [inline] |
maximum value of the array
Note: returns (T) 0 if length of array is 0, so check length beforehand
T array< T >::min | ( | ) | [inline] |
minimum value of the array
Note: returns (T) 0 if length of array is 0, so check length beforehand
access element at index idx
idx | element index to access |
access element at index idx
idx | element index to access |
combine arrays using OR operator
size of set union
void array< T >::print | ( | ) | [inline] |
prints the array to stdout
Note: This only works for certain types T
string * array< double >::printToString | ( | ) | [inline] |
Reimplemented in carray< T >.
string * array< T >::printToString | ( | ) | [inline] |
Put a single value in current array.
val | value to be set | |
idx | index at which the value should be placed |
Put one element of value val at position idx. The length of the array is changed if idx >= length of current array.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
ar2 | array containing the data to replace | |
idx | index at which ar2 should be placed | |
len | length of the part which should be replaced |
Array ar2 is put at position idx of the this array, overwriting the current content (up to len elements). The length of this array is increased if idx+len is larger that the current length. In the current array, len elements are reserved even if the length of ar2 is shorter.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
ar2 | array containing the data to replace | |
idx | index at which ar2 should be placed |
Array ar2 is put at position idx of the this array, overwriting the current content. The length of this array is increased if len(ar2)+idx is larger than the current array.
Put new data in current array.
ar2 | array containing the new data |
Array ar2 is put at position 0 of the this array, overwriting the current content. The length of this array is increased if ar2 is larger than the current array.
void array< T >::replace | ( | const array< T > & | ar2, | |
int32 | idx, | |||
int32 | len | |||
) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
ar2 | array containing the data to replace | |
idx | index at which ar2 should be placed | |
len | length of the part which should be replaced |
Note: everything from idx to idx+len of the array is replaced by ar2. The length of the array is changed accordingly.
Replace part of a array by new data.
ar2 | array containing the data to replace | |
idx | index at which ar2 should be placed |
Note: everything from idx to the end of the array is replaced by ar2. The length of the array is changed acordingly.
Replace this array by new data.
ar2 | array containing the data to replace |
Note: This array is replaced by ar2. The length of the array is now the length of ar2.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
val | value with which part of the array should be filled | |
num | number of values to be inserted | |
idx | index at which ar2 should be placed | |
len | length of the part which should be replaced |
Everything from idx to idx+len of the array is replaced by num values. The length of the array is changed acordingly.
Replace part of the array by num values.
val | value with which part of the array should be filled | |
num | number of values to be inserted | |
idx | index at which ar2 should be placed |
everything from idx to the end of the array is replaced by num values. The length of the array is changed acordingly.
Replace the array by num values.
val | value with which part of the array should be filled | |
num | number of values to be inserted |
Everything from the beginning to the end of the array is replaced by num values val. The length of the array will be num.
void array< T >::scale | ( | T | mult | ) |
multiply all components by mult
fill elements indexed by idxs array with val
get values of current array indexed by idxs
void array< T >::selectPut | ( | const array< T2 > & | ar2, | |
array< int32 > & | idxs | |||
) | [inline] |
fill elements indexed by idxs array with elements from ar2
access element at index idx
idx | element index to access |
subtract second array component by component
substract(boolean) ar2 from current array
size of set substraction (substract(boolean) ar2 from current array)
string * array< T >::toString | ( | ) | [inline] |
creates a string containing a copy of the array data
returns indices of non-zero elements
returns indices of elements equal to val
returns indices of elements greater than or equal to val
returns indices of elements greater than val
returns indices of elements less than or equal to val
returns indices of elements less than val