Re: Data structure design question
"syuga" <syuga2012@gmail.com> wrote in message
news:fd6f7fe0-83d4-43b6-9147-190ce356ede6@f41g2000pra.googlegroups.com...
Hi Folks,
I have a set of values (e.g integers from i = 1 to 255) and each value
( i ), can be associated with another set of values ( integers from j
= 1 to 50). A simple 2 dimensional array would map the set of values.
i.e for each i, what are the valid j can be found.
The problem is that most of the valid values of j for a given i are
few and it takes a lot of memory.
I would like to know of a better solution to this problem. Appreciate
your help.
0 1 2 3 4 5 6 7 8 .......
=============
1 | 0 0 0 1 0 1 0
2 | 1 0 0 1 1 0 0
3 |
4 |
Since the given values of J for each I is limited, just make the values a
vector. So you would have 255 vectors of ints. This can also be stored in
a vector of vectors but the initialization gets a litte hazy, so you might
want to wrap the given J's.
class JValues
{
private:
std::vector<i> Values;
public:
JValues() { };
JValues( std::vector<i>& Data ) {
Values = Data;
}
bool IsValid( int Number ) {
// find value here and return true or false
}
};
etc... whatever logic you want. If you need the exact code I could do it,
but you should try I think
Then either a pure array:
JValues[255] MyData;
or a vector of dta.
std::vector<JValues> MyData;
then you'll need to send the data to JValues what are the valid entries.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]