Nemo  2.3.46
DataTable< T > Class Template Reference

A class to aggregate structured data in an array. More...

#include <datatable.h>

+ Collaboration diagram for DataTable< T >:

Public Member Functions

 DataTable ()
 Default constructor. More...
 
 DataTable (unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
 Constructor. More...
 
 ~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. More...
 
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. More...
 
void free ()
 Deallocates all the allocated tables. More...
 
unsigned int length ()
 Returns the length of the table (total number of elements present). More...
 
T * getTable ()
 Accessor to the table array. More...
 
T * getGroup (unsigned int group)
 Accessor to a group array. More...
 
T * getClassWithinGroup (unsigned int group, unsigned int Class)
 Accessor to a class array whithin a group. More...
 
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'. More...
 
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'. More...
 
void increment (unsigned int group, unsigned int Class, unsigned int elmnt)
 Increments 'elmnt' of the class 'Class' in the group 'group' by one. More...
 
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'. More...
 
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'. More...
 
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'. More...
 
void divide (unsigned int group, unsigned int Class, unsigned int elmnt, T val)
 Subdivide 'elmnt' of the class 'Class' in the group 'group' by 'val'. More...
 
void init (T val)
 Sets all elements of the table to value 'val'. More...
 
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 More...
 
unsigned int _groups
 number of groups in the table More...
 
unsigned int _classes
 number of classes within each group More...
 
unsigned int ** _cumulClassSizes
 Stores the indexes of each class of each group present in the table. More...
 
unsigned int_cumulGroupSizes
 Stores the indexes of each group present in the table. More...
 
unsigned int ** _sizes
 
T * _table
 

Detailed Description

template<class T>
class DataTable< T >

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).

Constructor & Destructor Documentation

template<class T>
DataTable< T >::DataTable ( )
inline

Default constructor.

90 : _length(0), _groups(0), _classes(0), _cumulClassSizes(0), _cumulGroupSizes(0), _sizes(0), _table(0) { }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
unsigned int _length
length of the table
Definition: datatable.h:41
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
unsigned int ** _sizes
Definition: datatable.h:57
unsigned int _classes
number of classes within each group
Definition: datatable.h:45
template<class T>
DataTable< T >::DataTable ( unsigned int  nbgroups,
unsigned int  nbclasses,
unsigned int **  classSizes 
)
inline

Constructor.

Parameters
nbgroupsthe number of rows in the table, typically the number of patches
nbclassesan array of the sizes of each row, i.e. the Patch sizes
classSizesa matrix of the sizes of each class within each group
96  :
98  { allocate(nbgroups, nbclasses, classSizes); }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
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...
Definition: datatable.h:107
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
unsigned int _length
length of the table
Definition: datatable.h:41
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
unsigned int _classes
number of classes within each group
Definition: datatable.h:45
template<class T>
DataTable< T >::~DataTable ( )
inline
100 {free();}
void free()
Deallocates all the allocated tables.
Definition: datatable.h:189

Member Function Documentation

template<class T>
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.

Parameters
nbgroupsthe number of rows in the table, typically the number of patches
nbclassesthe number of classes within a group, e.g. the age-classes
classSizesa matrix (nbgroups X nbclasses) of the sizes of each class within each group

Referenced by TTNeutralGenesSH::allocateTables(), DataTable< unsigned int >::DataTable(), and DataTable< unsigned int >::update().

107  {
108  //#ifdef _DEBUG_
109  // message("DataTable::allocate:\n");
110  //#endif
111 
112  free();
113 
114  store_sizes(nbgroups, nbclasses, classSizes);
115 
116  _groups = nbgroups;
117  _classes = nbclasses;
118  _length = 0;
119 
120  _cumulClassSizes = new unsigned int*[_groups];
121 
122  for(unsigned int i = 0; i < _groups; i++){
123  _cumulClassSizes[i] = new unsigned int [_classes];
124  _cumulClassSizes[i][0] = 0;
125  for(unsigned int j = 1; j < _classes; ++j)
126  _cumulClassSizes[i][j] = _cumulClassSizes[i][j-1] + classSizes[i][j-1];
127  }
128 
129  _cumulGroupSizes = new unsigned int[_groups];
130 
131  _cumulGroupSizes[0] = 0;
132  for(unsigned int i = 1; i < _groups; i++){
134  for(unsigned int j = 0; j < _classes; ++j) {
135  _cumulGroupSizes[i] += classSizes[(i-1)][j];//total size of the previous group
136  _length += classSizes[i][j];//aggregate to compute total length
137  }
138  }
139  //add the sizes of first group classes to have the total length of the table
140  for(unsigned int j = 0; j < _classes; ++j)
141  _length += classSizes[0][j];
142 
143  _table = new T[_length];
144  //#ifdef _DEBUG_
145 // cout<<"DataTable::allocate:_table="<<_table<<endl;
146  //#endif
147  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
void free()
Deallocates all the allocated tables.
Definition: datatable.h:189
void store_sizes(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Definition: datatable.h:61
unsigned int _length
length of the table
Definition: datatable.h:41
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
unsigned int _classes
number of classes within each group
Definition: datatable.h:45
template<class T>
void DataTable< T >::divide ( unsigned int  group,
unsigned int  Class,
unsigned int  elmnt,
val 
)
inline

Subdivide 'elmnt' of the class 'Class' in the group 'group' by 'val'.

Referenced by TTNeutralGenesSH::setHeterozygosity().

252  {
253  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] /= val;
254  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
void DataTable< T >::free ( )
inline

Deallocates all the allocated tables.

Referenced by DataTable< unsigned int >::allocate(), and DataTable< unsigned int >::~DataTable().

189  {
190 // cout << "\ncalling DataTable::free()\n";
191 // cout << " pointer state: table="<<_table<<" cumulGroupSizes="<<_cumulGroupSizes
192 // <<"\n cumulClassSizes="<<_cumulClassSizes<<" sizes="<<_sizes
193 // <<endl;
194 
195  if(_table != NULL) delete [] _table;
196 
197  if(_cumulGroupSizes != NULL) delete [] _cumulGroupSizes;
198 // cout << " delete _cumulClassSizes\n";
199  if(_cumulClassSizes != NULL){
200  for(unsigned int i = 0; i < _groups; ++i) {
201 // cout << " "<<i<<":"<<_cumulClassSizes[i]<<endl;
202  delete [] _cumulClassSizes[i];}
203  delete [] _cumulClassSizes;
204  }
205 // cout << " delete _sizes\n";
206  if(_sizes != NULL){
207  for(unsigned int i = 0; i < _groups; ++i) delete [] _sizes[i];
208  delete [] _sizes;
209  }
210 
211  _table = NULL;
212  _cumulGroupSizes = NULL;
213  _cumulClassSizes = NULL;
214  _sizes = NULL;
215  _length = 0;
216 // cout << "DataTable::free() done\n";
217 }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
unsigned int _length
length of the table
Definition: datatable.h:41
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
unsigned int ** _sizes
Definition: datatable.h:57
template<class T>
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'.

Referenced by TTNeutralGenesSH::getHeterozygosity(), TTNeutralGenesSH::setAlleleTables(), TTNeutralGenesSH::setFst_li(), TTNeutralGenesSH::setFstatWeirCockerham(), TTNeutralGenesSH::setFstatWeirCockerham_MS(), TTNeutralGenesSH::setFstMatrix(), TTNeutralGenesSH::setHs(), TTNeutralGenesSH::setHs2(), TTNeutralGenesSH::setLociDivCounter(), TTNeutralGenesSH::setNeiGeneticDistance(), TTNeutralGenesFH::write_freq(), and TTNeutralGenesFH::write_varcompWC().

228  {
229  return _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ];
230  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
T* DataTable< T >::getClassWithinGroup ( unsigned int  group,
unsigned int  Class 
)
inline

Accessor to a class array whithin a group.

Referenced by TTQuantiSH::getSkewPerPatch(), and TTQuantiSH::setStats().

225  {
226  return &_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] ];}
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
T* DataTable< T >::getGroup ( unsigned int  group)
inline

Accessor to a group array.

Referenced by TTQuantiSH::setStats().

223 {return &_table[ _cumulGroupSizes[group] ];}
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
T * _table
Definition: datatable.h:59
template<class T>
unsigned int DataTable< T >::getNumClasses ( )
inline
259 {return _classes;}
unsigned int _classes
number of classes within each group
Definition: datatable.h:45
template<class T>
unsigned int DataTable< T >::getNumGroups ( )
inline

Referenced by TTNeutralGenesSH::getHeterozygosity(), TTNeutralGenesSH::setAlleleTables(), TTNeutralGenesSH::setFstat(), and TTNeutralGenesSH::setFstat2().

258 {return _groups;}
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
template<class T>
T* DataTable< T >::getTable ( )
inline

Accessor to the table array.

221 {return _table;}
T * _table
Definition: datatable.h:59
template<class T>
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.

Referenced by TTNeutralGenesSH::setAlleleTables().

236  {
237  ++_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ];
238  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
void DataTable< T >::init ( val)
inline

Sets all elements of the table to value 'val'.

Referenced by TTNeutralGenesSH::setAlleleTables(), and TTNeutralGenesSH::setHeteroTable().

256 {for(unsigned int i = 0; i < _length; ++i) _table[i] = val;}
unsigned int _length
length of the table
Definition: datatable.h:41
T * _table
Definition: datatable.h:59
template<class T>
unsigned int DataTable< T >::length ( )
inline

Returns the length of the table (total number of elements present).

219 {return _length;}
unsigned int _length
length of the table
Definition: datatable.h:41
template<class T>
void DataTable< T >::minus ( unsigned int  group,
unsigned int  Class,
unsigned int  elmnt,
val 
)
inline

Substracts 'val' from 'elmnt' in the class 'Class' in the group 'group'.

244  {
245  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] -= val;
246  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
void DataTable< T >::multiply ( unsigned int  group,
unsigned int  Class,
unsigned int  elmnt,
val 
)
inline

Multiplies 'elmnt' of the class 'Class' in the group 'group' by 'val'.

248  {
249  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] *= val;
250  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
void DataTable< T >::plus ( unsigned int  group,
unsigned int  Class,
unsigned int  elmnt,
val 
)
inline

Adds 'val' to 'elmnt' in the class 'Class' in the group 'group'.

Referenced by TTNeutralGenesSH::setHeteroTable().

240  {
241  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] += val;
242  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
void DataTable< T >::set ( unsigned int  group,
unsigned int  Class,
unsigned int  elmnt,
val 
)
inline

Sets the element 'elmnt' of the class 'Class' in the group 'group' to the value 'val'.

Referenced by TTNeutralGenesSH::setAlleleTables(), and store_quanti_trait_values().

232  {
233  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] = val;
234  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
template<class T>
void DataTable< T >::show_up ( )
inline
263  {
264  message("DataTable: got %i groups of %i classes; total length is %i.\n", _groups, _classes, _length);
265  }
void message(const char *message,...)
Definition: output.cc:40
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
unsigned int _length
length of the table
Definition: datatable.h:41
unsigned int _classes
number of classes within each group
Definition: datatable.h:45
template<class T>
unsigned int DataTable< T >::size ( unsigned int  i,
unsigned int  j 
)
inline

Referenced by TTQuantiSH::getSkewPerPatch(), and TTQuantiSH::setDataTables().

260 {return _sizes[i][j];}
unsigned int ** _sizes
Definition: datatable.h:57
template<class T>
bool DataTable< T >::sizeChange ( unsigned int  nbgroups,
unsigned int  nbclasses,
unsigned int **  classSizes 
)
inlineprivate

Referenced by DataTable< unsigned int >::update().

77  {
78  bool status = 0;
79  if( nbgroups != _groups || nbclasses != _classes ) return true;
80  else {
81  for (unsigned int i = 0; i < _groups; i++)
82  for (unsigned int j = 0; j < _classes; j++)
83  status |= _sizes[i][j] != classSizes[i][j];
84  }
85  return status;
86  }
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
unsigned int ** _sizes
Definition: datatable.h:57
unsigned int _classes
number of classes within each group
Definition: datatable.h:45
template<class T>
void DataTable< T >::store_sizes ( unsigned int  nbgroups,
unsigned int  nbclasses,
unsigned int **  classSizes 
)
inlineprivate

Referenced by DataTable< unsigned int >::allocate(), and DataTable< unsigned int >::update().

61  {
62 
63  if (_sizes != NULL) {
64  for(unsigned int i = 0; i < nbgroups; ++i) delete [] _sizes[i];
65  delete [] _sizes;
66  }
67 
68  _sizes = new unsigned int * [nbgroups];
69 
70  for(unsigned int i = 0; i < nbgroups; ++i) {
71  _sizes[i] = new unsigned int [nbclasses];
72  for(unsigned int j = 0; j < nbclasses; ++j)
73  _sizes[i][j] = classSizes[i][j];
74  }
75  }
unsigned int ** _sizes
Definition: datatable.h:57
template<class T>
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.

Parameters
nbgroupsthe number of rows in the table, typically the number of patches
nbclassesthe number of classes within a group, e.g. the age-class sizes
classSizesa matrix of the sizes of each class within each group

Referenced by TTQuantiSH::setDataTables(), and TTNeutralGenesSH::setHeteroTable().

154  {
155  //#ifdef _DEBUG_
156  // message("DataTable::update:\n");
157  //#endif
158  if( nbgroups != _groups || nbclasses != _classes )
159 
160  allocate(nbgroups, nbclasses, classSizes); //free() is called in allocate
161 
162  else if ( sizeChange(nbgroups, nbclasses, classSizes) ) {
163 
164  store_sizes(nbgroups, nbclasses, classSizes);
165 
166  for(unsigned int i = 0; i < _groups; i++){
167  for(unsigned int j = 1; j < _classes; ++j)
168  _cumulClassSizes[i][j] = _cumulClassSizes[i][j-1] + classSizes[i][j-1];
169  }
170  _length = 0;
171  _cumulGroupSizes[0] = 0;
172  for(unsigned int i = 1; i < _groups; i++){
174  for(unsigned int j = 0; j < _classes; ++j) {
175  _cumulGroupSizes[i] += classSizes[(i-1)][j];
176  _length += classSizes[i][j];
177  }
178  }
179 
180  for(unsigned int j = 0; j < _classes; ++j)
181  _length += classSizes[0][j];
182 
183  if(_table != NULL) delete [] _table;
184 
185  _table = new T[_length];
186  }
187  }
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
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...
Definition: datatable.h:107
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
bool sizeChange(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Definition: datatable.h:77
void store_sizes(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Definition: datatable.h:61
unsigned int _length
length of the table
Definition: datatable.h:41
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
T * _table
Definition: datatable.h:59
unsigned int _classes
number of classes within each group
Definition: datatable.h:45

Member Data Documentation

template<class T>
unsigned int DataTable< T >::_classes
private
template<class T>
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.

Referenced by DataTable< unsigned int >::free().

template<class T>
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.

Referenced by DataTable< unsigned int >::free().

template<class T>
unsigned int** DataTable< T >::_sizes
private

The documentation for this class was generated from the following file:

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR