Vector withing map: accessing values

M

Marcus

I have a vector within a vector within a map. The innermost vector
houses a struct with some ints and floats. The map keys off the
secondary vector which acts as a wrapper for multiple vector struct
entries for a specific key.

std::vector<Object> vec;
std::vector<std::vector <Object> > vecMain;
std::map<std::string,std::vector <std::vector <Object> > > map;

//Assuming I have loaded the vectors and map, how do I get at the vec
values if I have a key value?

std::map<std::string,std::vector <vector <Object> > >::iterator pos;
pos = map.find("abc");
if (pos != map.end()){

//...how should I handle the multiple loops here?

Any help would be very appreciated.
 
M

Mark P

Marcus said:
I have a vector within a vector within a map. The innermost vector
houses a struct with some ints and floats. The map keys off the
secondary vector which acts as a wrapper for multiple vector struct
entries for a specific key.

std::vector<Object> vec;
std::vector<std::vector <Object> > vecMain;
std::map<std::string,std::vector <std::vector <Object> > > map;

//Assuming I have loaded the vectors and map, how do I get at the vec
values if I have a key value?

std::map<std::string,std::vector <vector <Object> > >::iterator pos;
pos = map.find("abc");
if (pos != map.end()){

//...how should I handle the multiple loops here?

Just take it one level at a time. It may be easier to organize the
computation if you use references at each level. For example:

vector<vector<Object> >& vvo = pos->second;

// work with vvo as needed... loops, algorithms, indicies, etc.
 
D

Dakka

Marcus said:
I have a vector within a vector within a map. The innermost vector
houses a struct with some ints and floats. The map keys off the
secondary vector which acts as a wrapper for multiple vector struct
entries for a specific key.

std::vector<Object> vec;
std::vector<std::vector <Object> > vecMain;
std::map<std::string,std::vector <std::vector <Object> > > map;

//Assuming I have loaded the vectors and map, how do I get at the vec
values if I have a key value?

std::map<std::string,std::vector <vector <Object> > >::iterator pos;
pos = map.find("abc");
if (pos != map.end()){

//...how should I handle the multiple loops here?

Any help would be very appreciated.
This isn't that efficient and does nothing but I think it will give you
the idea....
-------------------------------------------------
#include <map>
#include <vector>
#include <string>
typedef std::map<std::string,std::vector <std::vector <int> > > Mvv;

int main()
{
Mvv mvv;
std::string key("test");
Mvv::iterator mvvit(mvv.find(key));

if (mvvit != mvv.end())
{
for (int ii(0); ii < mvvit->second.size(); ++ii)
for (int jj(0); jj < mvvit->second[ii].size(); ++jj)
mvvit->second[ii][jj] = 1;
}

return 0;
}
---------------------------------------------------

--dakka

*Dykstra's Observation:*
/If debugging is the process of removing bugs, then programming must be
the process of putting them in./
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top