Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
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

◆ DataTable() [1/2]

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

Default constructor.

89 : _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:54
unsigned int ** _sizes
Definition: datatable.h:56
T * _table
Definition: datatable.h:58
unsigned int _length
length of the table
Definition: datatable.h:40
unsigned int _groups
number of groups in the table
Definition: datatable.h:42
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:49
unsigned int _classes
number of classes within each group
Definition: datatable.h:44

◆ DataTable() [2/2]

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
95  :
97  { allocate(nbgroups, nbclasses, classSizes); }
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:106

References DataTable< T >::allocate().

◆ ~DataTable()

template<class T >
DataTable< T >::~DataTable ( )
inline
99 {free();}
void free()
Deallocates all the allocated tables.
Definition: datatable.h:188

References DataTable< T >::free().

Member Function Documentation

◆ allocate()

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
106  {
107  //#ifdef _DEBUG_
108  // message("DataTable::allocate:\n");
109  //#endif
110 
111  free();
112 
113  store_sizes(nbgroups, nbclasses, classSizes);
114 
115  _groups = nbgroups;
116  _classes = nbclasses;
117  _length = 0;
118 
119  _cumulClassSizes = new unsigned int*[_groups];
120 
121  for(unsigned int i = 0; i < _groups; i++){
122  _cumulClassSizes[i] = new unsigned int [_classes];
123  _cumulClassSizes[i][0] = 0;
124  for(unsigned int j = 1; j < _classes; ++j)
125  _cumulClassSizes[i][j] = _cumulClassSizes[i][j-1] + classSizes[i][j-1];
126  }
127 
128  _cumulGroupSizes = new unsigned int[_groups];
129 
130  _cumulGroupSizes[0] = 0;
131  for(unsigned int i = 1; i < _groups; i++){
133  for(unsigned int j = 0; j < _classes; ++j) {
134  _cumulGroupSizes[i] += classSizes[(i-1)][j];//total size of the previous group
135  _length += classSizes[i][j];//aggregate to compute total length
136  }
137  }
138  //add the sizes of first group classes to have the total length of the table
139  for(unsigned int j = 0; j < _classes; ++j)
140  _length += classSizes[0][j];
141 
142  _table = new T[_length];
143  //#ifdef _DEBUG_
144 // cout<<"DataTable::allocate:_table="<<_table<<endl;
145  //#endif
146  }
void store_sizes(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Definition: datatable.h:60

References DataTable< T >::_classes, DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, DataTable< T >::_groups, DataTable< T >::_length, DataTable< T >::_table, DataTable< T >::free(), and DataTable< T >::store_sizes().

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

+ Here is the caller graph for this function:

◆ divide()

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

251  {
252  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] /= val;
253  }

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

Referenced by TTNeutralGenesSH::setHeterozygosity().

+ Here is the caller graph for this function:

◆ free()

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

Deallocates all the allocated tables.

188  {
189 // cout << "\ncalling DataTable::free()\n";
190 // cout << " pointer state: table="<<_table<<" cumulGroupSizes="<<_cumulGroupSizes
191 // <<"\n cumulClassSizes="<<_cumulClassSizes<<" sizes="<<_sizes
192 // <<endl;
193 
194  if(_table != NULL) delete [] _table;
195 
196  if(_cumulGroupSizes != NULL) delete [] _cumulGroupSizes;
197 // cout << " delete _cumulClassSizes\n";
198  if(_cumulClassSizes != NULL){
199  for(unsigned int i = 0; i < _groups; ++i) {
200 // cout << " "<<i<<":"<<_cumulClassSizes[i]<<endl;
201  delete [] _cumulClassSizes[i];}
202  delete [] _cumulClassSizes;
203  }
204 // cout << " delete _sizes\n";
205  if(_sizes != NULL){
206  for(unsigned int i = 0; i < _groups; ++i) delete [] _sizes[i];
207  delete [] _sizes;
208  }
209 
210  _table = NULL;
211  _cumulGroupSizes = NULL;
212  _cumulClassSizes = NULL;
213  _sizes = NULL;
214  _length = 0;
215 // cout << "DataTable::free() done\n";
216 }

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, DataTable< T >::_groups, DataTable< T >::_length, DataTable< T >::_sizes, and DataTable< T >::_table.

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

+ Here is the caller graph for this function:

◆ get()

template<class T >
T DataTable< T >::get ( unsigned int  group,
unsigned int  Class,
unsigned int  elmnt 
)
inline

◆ getClassWithinGroup()

template<class T >
T* DataTable< T >::getClassWithinGroup ( unsigned int  group,
unsigned int  Class 
)
inline

Accessor to a class array whithin a group.

224  {
225  return &_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] ];}

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

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

+ Here is the caller graph for this function:

◆ getGroup()

template<class T >
T* DataTable< T >::getGroup ( unsigned int  group)
inline

Accessor to a group array.

222 {return &_table[ _cumulGroupSizes[group] ];}

References DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

Referenced by TTQuantiSH::setStats().

+ Here is the caller graph for this function:

◆ getNumClasses()

template<class T >
unsigned int DataTable< T >::getNumClasses ( )
inline
258 {return _classes;}

References DataTable< T >::_classes.

◆ getNumGroups()

template<class T >
unsigned int DataTable< T >::getNumGroups ( )
inline
257 {return _groups;}

References DataTable< T >::_groups.

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

+ Here is the caller graph for this function:

◆ getTable()

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

Accessor to the table array.

220 {return _table;}

References DataTable< T >::_table.

◆ increment()

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.

235  {
236  ++_table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ];
237  }

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

Referenced by TTNeutralGenesSH::setAlleleTables().

+ Here is the caller graph for this function:

◆ init()

template<class T >
void DataTable< T >::init ( val)
inline

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

255 {for(unsigned int i = 0; i < _length; ++i) _table[i] = val;}

References DataTable< T >::_length, and DataTable< T >::_table.

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

+ Here is the caller graph for this function:

◆ length()

template<class T >
unsigned int DataTable< T >::length ( )
inline

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

218 {return _length;}

References DataTable< T >::_length.

◆ minus()

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

243  {
244  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] -= val;
245  }

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

◆ multiply()

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

247  {
248  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] *= val;
249  }

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

◆ plus()

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

239  {
240  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] += val;
241  }

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

Referenced by TTNeutralGenesSH::setHeteroTable().

+ Here is the caller graph for this function:

◆ set()

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

231  {
232  _table[ _cumulGroupSizes[group] + _cumulClassSizes[group][Class] + elmnt ] = val;
233  }

References DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, and DataTable< T >::_table.

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

+ Here is the caller graph for this function:

◆ show_up()

template<class T >
void DataTable< T >::show_up ( )
inline
262  {
263  message("DataTable: got %i groups of %i classes; total length is %i.\n", _groups, _classes, _length);
264  }
void message(const char *message,...)
Definition: output.cc:39

References DataTable< T >::_classes, DataTable< T >::_groups, DataTable< T >::_length, and message().

◆ size()

template<class T >
unsigned int DataTable< T >::size ( unsigned int  i,
unsigned int  j 
)
inline
259 {return _sizes[i][j];}

References DataTable< T >::_sizes.

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

+ Here is the caller graph for this function:

◆ sizeChange()

template<class T >
bool DataTable< T >::sizeChange ( unsigned int  nbgroups,
unsigned int  nbclasses,
unsigned int **  classSizes 
)
inlineprivate
76  {
77  bool status = 0;
78  if( nbgroups != _groups || nbclasses != _classes ) return true;
79  else {
80  for (unsigned int i = 0; i < _groups; i++)
81  for (unsigned int j = 0; j < _classes; j++)
82  status |= _sizes[i][j] != classSizes[i][j];
83  }
84  return status;
85  }

References DataTable< T >::_classes, DataTable< T >::_groups, and DataTable< T >::_sizes.

Referenced by DataTable< T >::update().

+ Here is the caller graph for this function:

◆ store_sizes()

template<class T >
void DataTable< T >::store_sizes ( unsigned int  nbgroups,
unsigned int  nbclasses,
unsigned int **  classSizes 
)
inlineprivate
60  {
61 
62  if (_sizes != NULL) {
63  for(unsigned int i = 0; i < nbgroups; ++i) delete [] _sizes[i];
64  delete [] _sizes;
65  }
66 
67  _sizes = new unsigned int * [nbgroups];
68 
69  for(unsigned int i = 0; i < nbgroups; ++i) {
70  _sizes[i] = new unsigned int [nbclasses];
71  for(unsigned int j = 0; j < nbclasses; ++j)
72  _sizes[i][j] = classSizes[i][j];
73  }
74  }

References DataTable< T >::_sizes.

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

+ Here is the caller graph for this function:

◆ update()

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
153  {
154  //#ifdef _DEBUG_
155  // message("DataTable::update:\n");
156  //#endif
157  if( nbgroups != _groups || nbclasses != _classes )
158 
159  allocate(nbgroups, nbclasses, classSizes); //free() is called in allocate
160 
161  else if ( sizeChange(nbgroups, nbclasses, classSizes) ) {
162 
163  store_sizes(nbgroups, nbclasses, classSizes);
164 
165  for(unsigned int i = 0; i < _groups; i++){
166  for(unsigned int j = 1; j < _classes; ++j)
167  _cumulClassSizes[i][j] = _cumulClassSizes[i][j-1] + classSizes[i][j-1];
168  }
169  _length = 0;
170  _cumulGroupSizes[0] = 0;
171  for(unsigned int i = 1; i < _groups; i++){
173  for(unsigned int j = 0; j < _classes; ++j) {
174  _cumulGroupSizes[i] += classSizes[(i-1)][j];
175  _length += classSizes[i][j];
176  }
177  }
178 
179  for(unsigned int j = 0; j < _classes; ++j)
180  _length += classSizes[0][j];
181 
182  if(_table != NULL) delete [] _table;
183 
184  _table = new T[_length];
185  }
186  }
bool sizeChange(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Definition: datatable.h:76

References DataTable< T >::_classes, DataTable< T >::_cumulClassSizes, DataTable< T >::_cumulGroupSizes, DataTable< T >::_groups, DataTable< T >::_length, DataTable< T >::_table, DataTable< T >::allocate(), DataTable< T >::sizeChange(), and DataTable< T >::store_sizes().

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

+ Here is the caller graph for this function:

Member Data Documentation

◆ _classes

template<class T >
unsigned int DataTable< T >::_classes
private

◆ _cumulClassSizes

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< T >::allocate(), DataTable< T >::divide(), DataTable< T >::free(), DataTable< T >::get(), DataTable< T >::getClassWithinGroup(), DataTable< T >::increment(), DataTable< T >::minus(), DataTable< T >::multiply(), DataTable< T >::plus(), DataTable< T >::set(), and DataTable< T >::update().

◆ _cumulGroupSizes

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< T >::allocate(), DataTable< T >::divide(), DataTable< T >::free(), DataTable< T >::get(), DataTable< T >::getClassWithinGroup(), DataTable< T >::getGroup(), DataTable< T >::increment(), DataTable< T >::minus(), DataTable< T >::multiply(), DataTable< T >::plus(), DataTable< T >::set(), and DataTable< T >::update().

◆ _groups

template<class T >
unsigned int DataTable< T >::_groups
private

◆ _length

template<class T >
unsigned int DataTable< T >::_length
private

◆ _sizes

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

◆ _table


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

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR