I have the following data structure:
std::vector<std::vector<std::pair <std::vector<unsigned>,std::vector<unsigned> >, unsigned > > A;
containing the following data:
((7),(108,109)),5
((7),(108,109)),4
((7),(101,102,110)),3
((7),(101,102)),1
((7),(51)),2
((7),(51,54)),6
((7),(40,54,59)),7
((3),(108,109)),15
((3),(101,102,110)),13
((3),(101,102)),11
((3),(51)),12
((3),(51,54)),16
((3),(40,54,59)),17
((9),(108,109)),25
((9),(108,109)),24
((9),(108,109,110)),20
((9),(101,102,110)),23
((9),(111,112,120)),21
((9),(101,102)),29
((9),(51)),22
((9),(51,54)),26
((9),(40,54,59)),7
((8,2,10),(108,109)),25
((8,2,10),(108,109)),24
((8,2,10),(108,109,110)),20
((8,2,10),(101,102,110)),23
((8,2,10),(111,112,120)),21
((8,2,10),(101,102)),29
((8,2,10),(51)),22
((8,2,10),(51,54)),26
((8,2,10),(40,54,59)),7
((5,7),(108,109)),35
((5,7),(108,109)),34
((5,7),(108,109,110)),30
((5,7),(101,102,110)),33
((5,7),(111,112,120)),31
((5,7),(101,102)),39
((5,7),(51)),32
((5,7),(51,54)),36
((5,7),(40,54,59)),37
Now I want to arrange my data in the following manner:
((3),(101,102)),11
((3),(108,109)),15
((3),(101,102,110)),13
((7),(101,102)),1
((7),(108,109)),5
((7),(108,109)),4
((7),(101,102,110)),3
((9),(101,102)),29
((9),(108,109)),25
((9),(108,109)),24
((9),(101,102,110)),23
((9),(108,109,110)),20
((9),(111,112,120)),21
((5,7),(101,102)),39
((5,7),(108,109)),35
((5,7),(108,109)),34
((5,7),(101,102,110)),33
((5,7),(108,109,110)),30
((5,7),(111,112,120)),31
((8,2,10),(101,102)),29
((8,2,10),(108,109)),25
((8,2,10),(108,109)),24
((8,2,10),(101,102,110)),23
((8,2,10),(108,109,110)),20
((8,2,10),(111,112,120)),21
((3),(51)),12
((3),(51,54)),16
((3),(40,54,59)),17
((7),(51)),2
((7),(51,54)),6
((7),(40,54,59)),7
((9),(51)),22
((9),(51,54)),26
((9),(40,54,59)),7
((5,7),(51)),32
((5,7),(51,54)),36
((5,7),(40,54,59)),37
((8,2,10),(51)),22
((8,2,10),(51,54)),26
((8,2,10),(40,54,59)),7
The ordering is achieved by first sorting by size the first vector of the first pair<> in the pair<>. Then lexicographically sorting the vectors. The second vector of the second pair in the pair<> is also sorted first by size of size and then it is lexicographically sorted. The data as a whole is clustered according of the second vector of the first pair<> in the pair<> of vector A. i.e. the user specifies to cluster together all elements of A together according to: ((101,102),(108,109),(101,102,110),(108,109,110),(111,112,120)) and ((51),(51,54),(40,54,59)).
I know it is possible to sort by (i). first size and (ii). then lexicographically sorting the vectors. By using the following code:
bool mySort(const pair<vector<unsigned>,vector<unsigned> > &a , const pair<vector<unsigned>,vector<unsigned> > &b)
{
if (a.first.size() == b.first.size()) {
//If sizes of the vectors are equal
//Sort the graph lexicographically.
return std::lexicographical_compare(a.first.begin(),a.first.end(),b.first.begin(),b.first.end());pair<vector<unsigned>,vector<unsigned> > a
} else {
//Sort by size.
return a.first.size() < b.first.size();
}
}
int main()
{
std::vector<std::pair<std::vector<unsigned>,std::vector<unsigned> > > a;
std::sort(a.begin(),a.end(),mySort);
}
But I am not getting that how can I also cluster together the second vector of the first pair of pair of vectors of A while sorting ((i). by size (ii). and then lexicographical ordering). Can someone please help me with it.
Additionally the size of vector A which I have is very large. So, any solutions which can also be efficient will be an icing on the cake.
The version of gcc which I am using is: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
I am fine with if the same could be achieved in c or c++ using any data structure (as I am only interested in the specific ordering that I have specified).
Aucun commentaire:
Enregistrer un commentaire