SoPlex
|
Safe arrays of data objects. More...
#include <dataarray.h>
Public Member Functions | |
T & | operator[] (int n) |
reference n 'th element. | |
const T & | operator[] (int n) const |
reference n 'th const element. | |
T & | last () |
reference last element. | |
const T & | last () const |
reference last const element. | |
T * | get_ptr () |
get a C pointer to the data. | |
const T * | get_const_ptr () const |
get a const C pointer to the data. | |
void | append (const T &t) |
append element t . | |
void | append (int n, const T &t) |
append n elements with value t . | |
void | append (int n, const T t[]) |
append n elements from t . | |
void | append (const DataArray< T > &t) |
append all elements from t . | |
void | insert (int i, int n) |
insert n uninitialized elements before i 'th element. | |
void | insert (int i, int n, const T &t) |
insert n elements with value t before i 'the element. | |
void | insert (int i, int n, const T t[]) |
insert n elements from t before i 'the element. | |
void | insert (int i, const DataArray< T > &t) |
insert all elements from t before i 'th element. | |
void | remove (int n=0, int m=1) |
remove m elements starting at n . | |
void | removeLast (int m=1) |
remove m last elements. | |
void | clear () |
remove all elements. | |
int | size () const |
return nr. of elements. | |
void | reSize (int newsize) |
reset size to newsize . | |
int | max () const |
return maximum number of elements. | |
void | reMax (int newMax=1, int newSize=-1) |
reset maximum number of elements. | |
DataArray & | operator= (const DataArray &rhs) |
assignment operator | |
bool | isConsistent () const |
consistency check | |
DataArray (const DataArray &old) | |
copy constructor | |
DataArray (int p_size=0, int p_max=0, Real p_fac=1.2) | |
default constructor. | |
~DataArray () | |
destructor | |
Protected Attributes | |
Real | memFactor |
memory extension factor. | |
Private Attributes | |
int | thesize |
number of used elements in array data | |
int | themax |
the length of array data and | |
T * | data |
the array of elements | |
Safe arrays of data objects.
Class DataArray provides safe arrays of Data Objects. For general C++ objects (in contrast to data objects) class Array is provided which manages memory in a C++ compliant way.
The elements of an instance of DataArray can be accessed just like ordinary C++ array elements by means of the index operator[](). Safety is provided by
-DNDEBUG
).Moreover, DataArrays may easily be extended by inserting or appending elements to the DataArray or shrunken by removing elements. Method reSize(int n) resets the DataArrays length to n
thereby possibly appending elements or truncating the DataArray to the required size.
A DataArray may be used as arguments for standard C functions requiring pointers through the use of get_ptr() and get_const_ptr().
Internally, a DataArray object allocates a block of memory that fits up to max() elements, only size() of them are used. This makes extension and shrinking methods perform better.
Definition at line 74 of file dataarray.h.
copy constructor
Definition at line 328 of file dataarray.h.
References data, DataArray(), isConsistent(), max(), memFactor, soplex::spx_alloc(), themax, and thesize.
Referenced by append(), DataArray(), insert(), and operator=().
default constructor.
The constructor allocates an Array containing size
uninitialized elements. The internal array is allocated to have max
nonzeros, and the memory extension factor is set to fac
.
p_size | number of unitialised elements. |
p_max | maximum number of elements the array can hold. |
p_fac | value for memFactor. |
Definition at line 353 of file dataarray.h.
References data, isConsistent(), memFactor, soplex::spx_alloc(), themax, and thesize.
~DataArray | ( | ) |
void append | ( | const DataArray< T > & | t | ) |
append all elements from t
.
Definition at line 149 of file dataarray.h.
References DataArray(), insert(), and thesize.
void append | ( | const T & | t | ) |
void append | ( | int | n, |
const T & | t ) |
append n
elements with value t
.
Definition at line 139 of file dataarray.h.
void append | ( | int | n, |
const T | t[] ) |
append n
elements from t
.
Definition at line 144 of file dataarray.h.
void clear | ( | ) |
const T * get_const_ptr | ( | ) | const |
T * get_ptr | ( | ) |
get a C pointer to the data.
Definition at line 123 of file dataarray.h.
References data.
Referenced by SPxLPBase< Real >::added2Set(), ClassSet< T >::remove(), ClassSet< T >::remove(), DataSet< DATA >::remove(), DataSet< DATA >::remove(), LPColSetBase< Real >::remove(), LPRowSetBase< Real >::remove(), SVSetBase< Real >::remove(), SVSetBase< Real >::remove(), SPxLPBase< Real >::removeColRange(), SPxLPBase< Real >::removeCols(), SPxLPBase< Real >::removeCols(), SPxLPBase< Real >::removeRowRange(), SPxLPBase< Real >::removeRows(), and SPxLPBase< Real >::removeRows().
void insert | ( | int | i, |
const DataArray< T > & | t ) |
insert all elements from t
before i
'th element.
Definition at line 192 of file dataarray.h.
References data, DataArray(), insert(), and size().
void insert | ( | int | i, |
int | n ) |
void insert | ( | int | i, |
int | n, | ||
const T & | t ) |
insert n
elements with value t
before i
'the element.
Definition at line 170 of file dataarray.h.
void insert | ( | int | i, |
int | n, | ||
const T | t[] ) |
insert n
elements from t
before i
'the element.
Definition at line 182 of file dataarray.h.
bool isConsistent | ( | ) | const |
consistency check
Definition at line 311 of file dataarray.h.
References data, memFactor, SPX_MSG_INCONSISTENT, themax, and thesize.
Referenced by DataArray(), DataArray(), and operator=().
T & last | ( | ) |
const T & last | ( | ) | const |
reference last const element.
Definition at line 116 of file dataarray.h.
int max | ( | ) | const |
return maximum number of elements.
Even though the DataArray currently holds no more than size() elements, up to max() elements could be added without need to reallocated free store.
Definition at line 256 of file dataarray.h.
References themax.
Referenced by DataArray().
assignment operator
Definition at line 297 of file dataarray.h.
References data, DataArray(), isConsistent(), reSize(), and size().
T & operator[] | ( | int | n | ) |
const T & operator[] | ( | int | n | ) | const |
reference n
'th const element.
Definition at line 102 of file dataarray.h.
void reMax | ( | int | newMax = 1, |
int | newSize = -1 ) |
reset maximum number of elements.
The value of max() is reset to newMax
thereby setting size() to newSize
. However, if newSize
has a value <
0
(as the default argument does) size() remains unchanged and max() is set to MIN(size(), newMax). Hence, calling reMax() without the default arguments, will reduce the memory consumption to a minimum. In no instance max() will be set to a value less than 1 (even if specified).
Definition at line 271 of file dataarray.h.
References data, soplex::spx_alloc(), soplex::spx_free(), soplex::spx_realloc(), themax, and thesize.
Referenced by reSize().
void remove | ( | int | n = 0, |
int | m = 1 ) |
remove m
elements starting at n
.
Definition at line 202 of file dataarray.h.
void removeLast | ( | int | m = 1 | ) |
void reSize | ( | int | newsize | ) |
reset size to newsize
.
Resizing a DataArray to less than the previous size, involves discarding its last elements. Resizing to a larger value involves adding uninitialized elements (similar to append()). If neccessary, also memory will be reallocated.
newsize | the new number of elements the array can hold. |
Definition at line 239 of file dataarray.h.
References memFactor, reMax(), themax, and thesize.
Referenced by SPxLPBase< Real >::doAddCols(), SPxLPBase< Real >::doAddRows(), insert(), and operator=().
int size | ( | ) | const |
return nr. of elements.
Definition at line 227 of file dataarray.h.
References thesize.
Referenced by SPxLPBase< Real >::addCols(), SPxLPBase< Real >::addRows(), SPxLPBase< Real >::doAddCols(), SPxLPBase< Real >::doAddRows(), insert(), operator=(), remove(), and removeLast().
|
private |
the array of elements
Definition at line 81 of file dataarray.h.
Referenced by DataArray(), DataArray(), get_const_ptr(), get_ptr(), insert(), insert(), insert(), insert(), isConsistent(), last(), last(), operator=(), operator[](), operator[](), reMax(), remove(), and ~DataArray().
|
protected |
memory extension factor.
When a DataArray is reSize()d to more than max() elements, the new value for max() is not just set to the new size but rather to memFactor
* size
. This makes reSizeing perform better in codes where a DataArray is extended often by a small number of elements only.
Definition at line 90 of file dataarray.h.
Referenced by DataArray(), DataArray(), isConsistent(), and reSize().
|
private |
the length of array data and
Definition at line 80 of file dataarray.h.
Referenced by DataArray(), DataArray(), isConsistent(), max(), reMax(), and reSize().
|
private |
number of used elements in array data
Definition at line 79 of file dataarray.h.
Referenced by append(), append(), append(), append(), clear(), DataArray(), DataArray(), insert(), isConsistent(), last(), last(), operator[](), operator[](), reMax(), remove(), removeLast(), reSize(), and size().