I have elements a and b of two sets A and B. Now these are related to each other (0..1:n cardinality) so each a has at most one partner in B and each b can have several (at least one) associations to items in A. A is a set of integer pairs and B are integers.

Is there efficient way to store such a "bi-directional" map? A simple approach would be to use two maps:

map<pair<unsigned int, unsigned int>, unsigned int> AtoB
map<unsigned int, vector<pair<unsigned int, unsigned int> > > BtoA

But perhaps there is good way to deal with this more efficiently.

Thanks for your help

Edit
Report