61 void store_sizes (
unsigned int nbgroups,
unsigned int nbclasses,
unsigned int** classSizes) {
64 for(
unsigned int i = 0; i < nbgroups; ++i)
delete []
_sizes[i];
68 _sizes =
new unsigned int * [nbgroups];
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];
77 bool sizeChange (
unsigned int nbgroups,
unsigned int nbclasses,
unsigned int** classSizes) {
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];
96 DataTable(
unsigned int nbgroups,
unsigned int nbclasses,
unsigned int** classSizes) :
98 {
allocate(nbgroups, nbclasses, classSizes); }
107 inline void allocate (
unsigned int nbgroups,
unsigned int nbclasses,
unsigned int** classSizes) {
122 for(
unsigned int i = 0; i <
_groups; i++){
125 for(
unsigned int j = 1; j <
_classes; ++j)
132 for(
unsigned int i = 1; i <
_groups; i++){
134 for(
unsigned int j = 0; j <
_classes; ++j) {
140 for(
unsigned int j = 0; j <
_classes; ++j)
154 inline void update(
unsigned int nbgroups,
unsigned int nbclasses,
unsigned int** classSizes) {
160 allocate(nbgroups, nbclasses, classSizes);
162 else if (
sizeChange(nbgroups, nbclasses, classSizes) ) {
166 for(
unsigned int i = 0; i <
_groups; i++){
167 for(
unsigned int j = 1; j <
_classes; ++j)
172 for(
unsigned int i = 1; i <
_groups; i++){
174 for(
unsigned int j = 0; j <
_classes; ++j) {
180 for(
unsigned int j = 0; j <
_classes; ++j)
200 for(
unsigned int i = 0; i <
_groups; ++i) {
207 for(
unsigned int i = 0; i <
_groups; ++i)
delete []
_sizes[i];
228 inline T
get (
unsigned int group,
unsigned int Class,
unsigned int elmnt) {
232 inline void set (
unsigned int group,
unsigned int Class,
unsigned int elmnt, T val) {
236 inline void increment (
unsigned int group,
unsigned int Class,
unsigned int elmnt) {
240 inline void plus (
unsigned int group,
unsigned int Class,
unsigned int elmnt, T val) {
244 inline void minus (
unsigned int group,
unsigned int Class,
unsigned int elmnt, T val) {
248 inline void multiply (
unsigned int group,
unsigned int Class,
unsigned int elmnt, T val) {
252 inline void divide (
unsigned int group,
unsigned int Class,
unsigned int elmnt, T val) {
260 unsigned int size (
unsigned int i,
unsigned int j) {
return _sizes[i][j];}
A class to aggregate structured data in an array.
Definition: datatable.h:37
void show_up()
Definition: datatable.h:262
DataTable(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Constructor.
Definition: datatable.h:96
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'.
Definition: datatable.h:244
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
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'.
Definition: datatable.h:232
bool sizeChange(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Definition: datatable.h:77
unsigned int size(unsigned int i, unsigned int j)
Definition: datatable.h:260
~DataTable()
Definition: datatable.h:100
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'.
Definition: datatable.h:252
unsigned int getNumClasses()
Definition: datatable.h:259
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'.
Definition: datatable.h:240
void store_sizes(unsigned int nbgroups, unsigned int nbclasses, unsigned int **classSizes)
Definition: datatable.h:61
void free()
Deallocates all the allocated tables.
Definition: datatable.h:189
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'.
Definition: datatable.h:228
T * getTable()
Accessor to the table array.
Definition: datatable.h:221
unsigned int * _cumulGroupSizes
Stores the indexes of each group present in the table.
Definition: datatable.h:55
unsigned int getNumGroups()
Definition: datatable.h:258
unsigned int ** _sizes
Definition: datatable.h:57
T * _table
Definition: datatable.h:59
DataTable()
Default constructor.
Definition: datatable.h:90
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.
Definition: datatable.h:154
void init(T val)
Sets all elements of the table to value 'val'.
Definition: datatable.h:256
T * getGroup(unsigned int group)
Accessor to a group array.
Definition: datatable.h:223
unsigned int _length
length of the table
Definition: datatable.h:41
T * getClassWithinGroup(unsigned int group, unsigned int Class)
Accessor to a class array whithin a group.
Definition: datatable.h:225
unsigned int _groups
number of groups in the table
Definition: datatable.h:43
unsigned int length()
Returns the length of the table (total number of elements present).
Definition: datatable.h:219
unsigned int ** _cumulClassSizes
Stores the indexes of each class of each group present in the table.
Definition: datatable.h:50
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'.
Definition: datatable.h:248
unsigned int _classes
number of classes within each group
Definition: datatable.h:45
void increment(unsigned int group, unsigned int Class, unsigned int elmnt)
Increments 'elmnt' of the class 'Class' in the group 'group' by one.
Definition: datatable.h:236
void message(const char *message,...)
Definition: output.cc:40