|
Nemo
2.2.0
|
A class to aggregate structured data in an array. More...
#include <datatable.h>
Collaboration diagram for DataTable< T >:Public Member Functions | |
| DataTable () | |
| Default constructor. | |
| DataTable (unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes) | |
| Constructor. | |
| ~DataTable () | |
| void | allocate (unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes) |
| Creates a table of size given by the sum of all classes passed by the 'classSizes' matrix. | |
| void | update (unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes) |
| Updates the group and classe sizes and re-allocates the table according to its new length. | |
| void | free () |
| Deallocates all the allocated tables. | |
| unsigned int | length () |
| Returns the length of the table (total number of elements present). | |
| T * | getTable () |
| Accessor to the table array. | |
| T * | getGroup (unsigned int group) |
| Accessor to a group array. | |
| T * | getClassWithinGroup (unsigned int group, unsigned int Class) |
| Accessor to a class array whithin a group. | |
| T | get (unsigned int group, unsigned int Class, unsigned int elmnt) |
| Returns value stored of the element 'elmnt' of the class 'Class' in the group 'group'. | |
| void | set (unsigned int group, unsigned int Class, unsigned int elmnt, T val) |
| Sets the element 'elmnt' of the class 'Class' in the group 'group' to the value 'val'. | |
| void | increment (unsigned int group, unsigned int Class, unsigned int elmnt) |
| Increments 'elmnt' of the class 'Class' in the group 'group' by one. | |
| void | plus (unsigned int group, unsigned int Class, unsigned int elmnt, T val) |
| Adds 'val' to 'elmnt' in the class 'Class' in the group 'group'. | |
| void | minus (unsigned int group, unsigned int Class, unsigned int elmnt, T val) |
| Substracts 'val' from 'elmnt' in the class 'Class' in the group 'group'. | |
| void | multiply (unsigned int group, unsigned int Class, unsigned int elmnt, T val) |
| Multiplies 'elmnt' of the class 'Class' in the group 'group' by 'val'. | |
| void | subdivide (unsigned int group, unsigned int Class, unsigned int elmnt, T val) |
| Subdivide 'elmnt' of the class 'Class' in the group 'group' by 'val'. | |
| void | init (T val) |
| Sets all elements of the table to value 'val'. | |
| unsigned int | getNumGroups () |
| unsigned int | getNumClasses () |
| unsigned int | size (unsigned int i, unsigned int j) |
| void | show_up () |
Private Member Functions | |
| void | store_sizes (unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes) |
| bool | sizeChange (unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes) |
Private Attributes | |
| unsigned int | _length |
| length of the table | |
| unsigned int | _groups |
| number of groups in the table | |
| unsigned int | _classes |
| number of classes within each group | |
| unsigned int ** | _cumulClassSizes |
| Stores the indexes of each class of each group present in the table. | |
| unsigned int * | _cumulGroupSizes |
| Stores the indexes of each group present in the table. | |
| unsigned int ** | _sizes |
| T * | _table |
A class to aggregate structured data in an array.
The information is subdivided into groups (e.g., patch) themselves structured in classes (e.g., age or sex classes).
Definition at line 37 of file datatable.h.
Default constructor.
Definition at line 90 of file datatable.h.
: _length(0), _groups(0), _classes(0), _cumulClassSizes(0), _cumulGroupSizes(0), _sizes(0), _table(0) { }
| DataTable< T >::DataTable | ( | unsigned int | nbgroups, |
| unsigned int | nbclasses, | ||
| unsigned int ** | classSizes | ||
| ) | [inline] |
Constructor.
| nbgroups | the number of rows in the table, typically the number of patches |
| nbclasses | an array of the sizes of each row, i.e. the Patch sizes |
| classSizes | a matrix of the sizes of each class within each group |
Definition at line 96 of file datatable.h.
: _length(0), _groups(0), _classes(0), _cumulClassSizes(0), _cumulGroupSizes(0), _table(0) { allocate(nbgroups, nbclasses, classSizes); }
Definition at line 100 of file datatable.h.
{free();}
| void DataTable< T >::allocate | ( | unsigned int | nbgroups, |
| unsigned int | nbclasses, | ||
| unsigned int ** | classSizes | ||
| ) | [inline] |
Creates a table of size given by the sum of all classes passed by the 'classSizes' matrix.
| nbgroups | the number of rows in the table, typically the number of patches |
| nbclasses | the number of classes within a group, e.g. the age-classes |
| classSizes | a matrix (nbgroups X nbclasses) of the sizes of each class within each group |
Definition at line 107 of file datatable.h.
Referenced by TTNeutralGenesSH::allocateTables(), DataTable< unsigned int >::DataTable(), DataTable< unsigned int >::update(), and TTNeutralGenesFH::write_varcompWC().
{
//#ifdef _DEBUG_
// message("DataTable::allocate:\n");
//#endif
free();
store_sizes(nbgroups, nbclasses, classSizes);
_groups = nbgroups;
_classes = nbclasses;
_length = 0;
_cumulClassSizes = new unsigned int*[_groups];
for(unsigned int i = 0; i < _groups; i++){
_cumulClassSizes[i] = new unsigned int [_classes];
_cumulClassSizes[i][0] = 0;
for(unsigned int j = 1; j < _classes; ++j)
_cumulClassSizes[i][j] = _cumulClassSizes[i][j-1] + classSizes[i][j-1];
}
_cumulGroupSizes = new unsigned int[_groups];
_cumulGroupSizes[0] = 0;
for(unsigned int i = 1; i < _groups; i++){
_cumulGroupSizes[i] = _cumulGroupSizes[i-1];
for(unsigned int j = 0; j < _classes; ++j) {
_cumulGroupSizes[i] += classSizes[(i-1)][j];//total size of the previous group
_length += classSizes[i][j];//aggregate to compute total length
}
}
//add the sizes of first group classes to have the total length of the table
for(unsigned int j = 0; j < _classes; ++j)
_length += classSizes[0][j];
_table = new T[_length];
//#ifdef _DEBUG_
// message("DataTable::allocate:_table = 0x%x\n",_table);
//#endif
}
| void DataTable< T >::free | ( | ) | [inline] |
Deallocates all the allocated tables.
Definition at line 189 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), and DataTable< unsigned int >::~DataTable().
{
if(_table != NULL) delete [] _table;
if(_cumulGroupSizes != NULL) delete [] _cumulGroupSizes;
if(_cumulClassSizes != NULL){
for(unsigned int i = 0; i < _groups; ++i) delete [] _cumulClassSizes[i];
delete [] _cumulClassSizes;
}
if(_sizes != NULL){
for(unsigned int i = 0; i < _groups; ++i) delete [] _sizes[i];
delete [] _sizes;
}
_table = NULL;
_cumulGroupSizes = NULL;
_cumulClassSizes = NULL;
_sizes = NULL;
_length = 0;
}
| T DataTable< T >::get | ( | unsigned int | group, |
| unsigned int | Class, | ||
| unsigned int | elmnt | ||
| ) | [inline] |
Returns value stored of the element 'elmnt' of the class 'Class' in the group 'group'.
Definition at line 220 of file datatable.h.
Referenced by TTNeutralGenesFH::write_freq(), and TTNeutralGenesFH::write_varcompWC().
{
return _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ];
}
| T* DataTable< T >::getClassWithinGroup | ( | unsigned int | group, |
| unsigned int | Class | ||
| ) | [inline] |
Accessor to a class array whithin a group.
Definition at line 217 of file datatable.h.
{
return &_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] ];}
| T* DataTable< T >::getGroup | ( | unsigned int | group | ) | [inline] |
Accessor to a group array.
Definition at line 215 of file datatable.h.
{return &_table[ _cumulGroupSizes[group] ];}
| unsigned int DataTable< T >::getNumClasses | ( | ) | [inline] |
Definition at line 251 of file datatable.h.
{return _classes;}
| unsigned int DataTable< T >::getNumGroups | ( | ) | [inline] |
Definition at line 250 of file datatable.h.
{return _groups;}
| T* DataTable< T >::getTable | ( | ) | [inline] |
| void DataTable< T >::increment | ( | unsigned int | group, |
| unsigned int | Class, | ||
| unsigned int | elmnt | ||
| ) | [inline] |
Increments 'elmnt' of the class 'Class' in the group 'group' by one.
Definition at line 228 of file datatable.h.
{
++_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ];
}
| void DataTable< T >::init | ( | T | val | ) | [inline] |
Sets all elements of the table to value 'val'.
Definition at line 248 of file datatable.h.
| unsigned int DataTable< T >::length | ( | ) | [inline] |
Returns the length of the table (total number of elements present).
Definition at line 211 of file datatable.h.
{return _length;}
| void DataTable< T >::minus | ( | unsigned int | group, |
| unsigned int | Class, | ||
| unsigned int | elmnt, | ||
| T | val | ||
| ) | [inline] |
Substracts 'val' from 'elmnt' in the class 'Class' in the group 'group'.
Definition at line 236 of file datatable.h.
{
_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] -= val;
}
| void DataTable< T >::multiply | ( | unsigned int | group, |
| unsigned int | Class, | ||
| unsigned int | elmnt, | ||
| T | val | ||
| ) | [inline] |
Multiplies 'elmnt' of the class 'Class' in the group 'group' by 'val'.
Definition at line 240 of file datatable.h.
{
_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] *= val;
}
| void DataTable< T >::plus | ( | unsigned int | group, |
| unsigned int | Class, | ||
| unsigned int | elmnt, | ||
| T | val | ||
| ) | [inline] |
Adds 'val' to 'elmnt' in the class 'Class' in the group 'group'.
Definition at line 232 of file datatable.h.
{
_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] += val;
}
| void DataTable< T >::set | ( | unsigned int | group, |
| unsigned int | Class, | ||
| unsigned int | elmnt, | ||
| T | val | ||
| ) | [inline] |
Sets the element 'elmnt' of the class 'Class' in the group 'group' to the value 'val'.
Definition at line 224 of file datatable.h.
{
_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] = val;
}
| void DataTable< T >::show_up | ( | ) | [inline] |
| unsigned int DataTable< T >::size | ( | unsigned int | i, |
| unsigned int | j | ||
| ) | [inline] |
Definition at line 252 of file datatable.h.
{return _sizes[i][j];}
| bool DataTable< T >::sizeChange | ( | unsigned int | nbgroups, |
| unsigned int | nbclasses, | ||
| unsigned int ** | classSizes | ||
| ) | [inline, private] |
Definition at line 77 of file datatable.h.
Referenced by DataTable< unsigned int >::update().
| void DataTable< T >::store_sizes | ( | unsigned int | nbgroups, |
| unsigned int | nbclasses, | ||
| unsigned int ** | classSizes | ||
| ) | [inline, private] |
Definition at line 61 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), and DataTable< unsigned int >::update().
{
if (_sizes != NULL) {
for(unsigned int i = 0; i < nbgroups; ++i) delete [] _sizes[i];
delete [] _sizes;
}
_sizes = new unsigned int * [nbgroups];
for(unsigned int i = 0; i < nbgroups; ++i) {
_sizes[i] = new unsigned int [nbclasses];
for(unsigned int j = 0; j < nbclasses; ++j)
_sizes[i][j] = classSizes[i][j];
}
}
| void DataTable< T >::subdivide | ( | unsigned int | group, |
| unsigned int | Class, | ||
| unsigned int | elmnt, | ||
| T | val | ||
| ) | [inline] |
Subdivide 'elmnt' of the class 'Class' in the group 'group' by 'val'.
Definition at line 244 of file datatable.h.
{
_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] /= val;
}
| void DataTable< T >::update | ( | unsigned int | nbgroups, |
| unsigned int | nbclasses, | ||
| unsigned int ** | classSizes | ||
| ) | [inline] |
Updates the group and classe sizes and re-allocates the table according to its new length.
| nbgroups | the number of rows in the table, typically the number of patches |
| nbclasses | the number of classes within a group, e.g. the age-class sizes |
| classSizes | a matrix of the sizes of each class within each group |
Definition at line 154 of file datatable.h.
{
//#ifdef _DEBUG_
// message("DataTable::update:\n");
//#endif
if( nbgroups != _groups || nbclasses != _classes )
allocate(nbgroups, nbclasses, classSizes); //free() is called in allocate
else if ( sizeChange(nbgroups, nbclasses, classSizes) ) {
store_sizes(nbgroups, nbclasses, classSizes);
for(unsigned int i = 0; i < _groups; i++){
for(unsigned int j = 1; j < _classes; ++j)
_cumulClassSizes[i][j] = _cumulClassSizes[i][j-1] + classSizes[i][j-1];
}
_length = 0;
_cumulGroupSizes[0] = 0;
for(unsigned int i = 1; i < _groups; i++){
_cumulGroupSizes[i] = _cumulGroupSizes[i-1];
for(unsigned int j = 0; j < _classes; ++j) {
_cumulGroupSizes[i] += classSizes[(i-1)][j];
_length += classSizes[i][j];
}
}
for(unsigned int j = 0; j < _classes; ++j)
_length += classSizes[0][j];
if(_table != NULL) delete [] _table;
_table = new T[_length];
}
}
number of classes within each group
Definition at line 45 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), DataTable< unsigned int >::getNumClasses(), DataTable< unsigned int >::show_up(), DataTable< unsigned int >::sizeChange(), and DataTable< unsigned int >::update().
unsigned int** DataTable< T >::_cumulClassSizes [private] |
Stores the indexes of each class of each group present in the table.
the aggregated sizes of each classe within each group given by: size(class i!=0) = sum of size( (class 0) to (class i-1) ) and size(class i=0) = 0. This is repeated for each group.
Definition at line 50 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), DataTable< unsigned int >::free(), DataTable< unsigned int >::get(), DataTable< unsigned int >::getClassWithinGroup(), DataTable< unsigned int >::increment(), DataTable< unsigned int >::minus(), DataTable< unsigned int >::multiply(), DataTable< unsigned int >::plus(), DataTable< unsigned int >::set(), DataTable< unsigned int >::subdivide(), and DataTable< unsigned int >::update().
unsigned int* DataTable< T >::_cumulGroupSizes [private] |
Stores the indexes of each group present in the table.
the aggregated sizes of each group with size(group i=0) = 0 and size(group i!=0) = sum of size( (group 0) to (group i-1)) where the group sizes are the sum of the classe sizes of the groups.
Definition at line 55 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), DataTable< unsigned int >::free(), DataTable< unsigned int >::get(), DataTable< unsigned int >::getClassWithinGroup(), DataTable< unsigned int >::getGroup(), DataTable< unsigned int >::increment(), DataTable< unsigned int >::minus(), DataTable< unsigned int >::multiply(), DataTable< unsigned int >::plus(), DataTable< unsigned int >::set(), DataTable< unsigned int >::subdivide(), and DataTable< unsigned int >::update().
number of groups in the table
Definition at line 43 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), DataTable< unsigned int >::free(), DataTable< unsigned int >::getNumGroups(), DataTable< unsigned int >::show_up(), DataTable< unsigned int >::sizeChange(), and DataTable< unsigned int >::update().
length of the table
Definition at line 41 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), DataTable< unsigned int >::free(), DataTable< unsigned int >::init(), DataTable< unsigned int >::length(), DataTable< unsigned int >::show_up(), and DataTable< unsigned int >::update().
Definition at line 57 of file datatable.h.
Referenced by DataTable< unsigned int >::free(), DataTable< unsigned int >::size(), DataTable< unsigned int >::sizeChange(), and DataTable< unsigned int >::store_sizes().
Definition at line 59 of file datatable.h.
Referenced by DataTable< unsigned int >::allocate(), DataTable< unsigned int >::free(), DataTable< unsigned int >::get(), DataTable< unsigned int >::getClassWithinGroup(), DataTable< unsigned int >::getGroup(), DataTable< unsigned int >::getTable(), DataTable< unsigned int >::increment(), DataTable< unsigned int >::init(), DataTable< unsigned int >::minus(), DataTable< unsigned int >::multiply(), DataTable< unsigned int >::plus(), DataTable< unsigned int >::set(), DataTable< unsigned int >::subdivide(), and DataTable< unsigned int >::update().
1.7.5.1 -- Nemo is hosted by