Hi:

I need to write a program that essentially needs to mane a list of a list of a list (that's right 3 times) of a certain class I created. I was having some efficiency problems so I decided to change all of the accesses to the structure form structure[i][j][k] to using the .at() function. I wrote a little code just to test this:

This is the Class named Tile.h
Qt Code:
  1. class Tile
  2. {
  3. public:
  4. Tile(qreal p, QList<quint16>);
  5. Tile();
  6.  
  7. //Definition of basic operations
  8. bool operator == (Tile t);
  9.  
  10. //Definition of sets and getters.
  11. QList<quint16> Indexes(){return indexes;}
  12. qreal param(){return parameter;}
  13. void setParam(qreal p){parameter = p;}
  14. void setIndexes(QList<quint16> ind){indexes = ind;}
  15.  
  16. //Function use Mainly for Debugging
  17. QString toString();
  18.  
  19. virtual ~Tile();
  20.  
  21. private:
  22. qreal parameter;
  23. QList<quint16> indexes;
  24. };
To copy to clipboard, switch view to plain text mode 

And the Tile.cpp
Qt Code:
  1. Tile::Tile(qreal p, QList<quint16> ind){
  2. indexes = ind;
  3. parameter = p;
  4. elegibility = 0;
  5. }
  6.  
  7. Tile::Tile(){
  8. parameter = 0;
  9. }
  10.  
  11. /****************Operators**************************/
  12. bool Tile::operator == (Tile t){
  13. QList<quint16> comp = t.Indexes();
  14. bool res = true;
  15. for (int i = 0; i < comp.size(); i++){
  16. if (comp.at(i) != indexes.at(i)){
  17. res = false;
  18. break;
  19. }
  20. }
  21. return res;
  22. }
  23.  
  24. /***********toString******************/
  25. QString Tile::toString(){
  26. QString ws = "";
  27. for (int i = 0; i < indexes.size(); i++){
  28. ws = ws + " " + QString::number(indexes.at(i));
  29. }
  30.  
  31. if(indexes.size() == 0){
  32. ws = "Nothing to show: Value is: " + QString::number(parameter);
  33. }
  34.  
  35. return ws;
  36. }
  37.  
  38. Tile::~Tile(){
  39. }
To copy to clipboard, switch view to plain text mode 

Then I wrote this code in a constructor just to test using this
Qt Code:
  1. int Im = 5;
  2. int Jm = 10;
  3. int Km = 6000;
  4. for (int i = 0; i < Im; i++){
  5. QVector < QVector<Tile> > temp2;
  6. for(int j = 0; j < Jm; j++){
  7. QVector<Tile> temp;
  8. for (int k = 0; k < Km; k++){
  9. QList<quint16> ind;
  10. ind << k;
  11. Tile t(0,ind);
  12. temp << t;
  13. }
  14. temp2 << temp;
  15. }
  16. test << temp2;
  17. }
To copy to clipboard, switch view to plain text mode 

Where test is defined by:
Qt Code:
  1. QVector < QVector< QVector<Tile> > > test;
To copy to clipboard, switch view to plain text mode 

So then I write this line in a button action just to see if it would compile
Qt Code:
  1. test.at(2).at(5).at(3940).setParam(test.at(2).at(5).at(3940).param() + 15.0);
To copy to clipboard, switch view to plain text mode 

And it doesn't and I get these two errors
passing ‘const Tile’ as ‘this’ argument of ‘qreal Tile:aram()’ discards qualifiers
passing ‘const Tile’ as ‘this’ argument of ‘void Tile::setParam(qreal)’ discards qualifiers

So I change it to this in order for it to work
Qt Code:
  1. test[2][5][3940].setParam(test[2][5][3940].param() + 15.0);
To copy to clipboard, switch view to plain text mode 

And this works but according to the Qt documentation [] is a lot more inefficient that at(). So I want it to change it to see if my algorithm would go a bit faster.

So my question is are there any suggestion on how to make this a bit more efficient to see if I can shave off some minutes to the my algortihms runs or am I just stuck with the slow program. Or maybe on how could I manage a list of a list of a list of classes in a more efficient way.

Thanks for any help