PDA

View Full Version : lookup table



georgie
11th May 2006, 13:53
what do you think is an efficient way of implementing a lookup table in c++

i'd use a vector or some other safe container, except calling push_back 400 times seems ridiculous.....

and i've currently got it as a cstyle array, but that is giving me weirrrrrrrrd results....



class LookupTable: public QWidget
{
public:
LookupTable();
int lookupElectrodeNumber(int i);
private:
int base_filter[21][13];
int id_filter[13][21];
int number_to_filter [100];
};
#endif//LOOKUP_TABLE_



LookupTable::LookupTable()
{

int::number_to_filter[] = { blah blah blah....a heck of a lot of numbers};

}

int LookupTable::lookupElectrodeNumber(int i)
{
return number_to_filter[i];
}


seems simple....but gives wacky stuff....

zlatko
11th May 2006, 16:13
First of all cut this code


int base_filter[21][13];
int id_filter[13][21];

if its not actual :)

Then show how do you init your vector,how do you call method lookupElectrodeNumber and what his retturn ? ;)

jacek
11th May 2006, 16:54
LookupTable::LookupTable()
{

int::number_to_filter[] = { blah blah blah....a heck of a lot of numbers};

}
You create a local variable, instead of initializing the number_to_filter member variable.

Does the contents of base_filter, id_filter and number_to_filter change?

georgie
12th May 2006, 03:41
no....it's pre defined (for a weird numbering system of nodes which goes in a quasi hexagonal fashion) and won't change

ball
12th May 2006, 04:08
How about using QMap class?

wysota
12th May 2006, 08:58
How about a global static predefined array?


static int base_filter[21][13] = { {1...21}, {22...42}, ...};

jacek
12th May 2006, 10:57
How about a global static predefined array?
I would do it this way:

namespace
{
const int base_filter[21][13] = { { 1, ..., 21 }, { 22, ..., 42 }, ... };
}