I want to use a C++ map structure, such as map<vector<DFSCode>, vector<PDB>> candidate
, DFSCode and PDB are two structures I define.
class DFS {
public:
int from;
int to;
int fromlabel;
int elabel;
int tolabel;
DFS(): from(0), to(0), fromlabel(0), elabel(0), tolabel(0) {};
};
struct DFSCode: public vector <DFS> {
public:
void push (int from, int to, int fromlabel, int elabel, int tolabel)
{
resize (size() + 1);
DFS &d = (*this)[size()-1];
d.from = from;
d.to = to;
d.fromlabel = fromlabel;
d.elabel = elabel;
d.tolabel = tolabel;
}
void pop () { resize (size()-1); }
};
class PDB {
public:
unsigned int tid;
unsigned int gid;
void push(int did, int vid, int vlabel)
{
tuple[did].vid = vid;
tuple[did].vlabel = vlabel;
}
PDB(): tid(0), gid(0), tuple(0) {};
};
I will generate a lot of data which contain vector<DFSCode>
and PDB
, since one vector<DFSCode>
may have many PDB
, I want to use vector<PDB>
to store them.
What I want to do is:
vector<DFSCode> tempdfscodeList;
PDB temppdb;
map<vector<DFSCode>, vector<PDB>> candidate;
for each `vector<DFSCode>` and `PDB` pair I generate
candidate[tempdfscodeList].push_back(temppdb);
The first question is: Does above code satisfied my expectation that "one vector<DFSCode>
contain many PDB
"?
The second question is: I know I have to implement a comparable method of map, since I use vector<DFSCode>
as my key, but I don't know how to implement. I try to write one. But it seems not satisfied my expectation that "one vector<DFSCode>
contain many PDB
", can anyone help me? :)
class dfscodeListCompare { // compare vector<DFSCode>
public:
bool operator() (const vector<DFSCode> &c1, const vector<DFSCode> &c2) const
{
for(int I = 0; I < c1.size(); I++) {
if(c1[I].size() == c2[I].size()) { // the size must be the same
for(int j = 0; j < c1[I].size(); j++) {
if((c1[I][j].from != c2[I][j].from) || (c1[I][j].to != c2[I][j].to) || (c1[I][j].fromlabel != c2[I][j].fromlabel) || (c1[I][j].elabel != c2[I][j].elabel) || (c1[I][j].tolabel != c2[I][j].tolabel))
return false; // if there exist one different
}
}
else
return false;
}
return true; // pass all condition
}
};