Re: What data container should I use with two different keys?
Rupert <rswarbrick@googlemail.com> wrote:
I have the problem that I want to store some information (in a class
called ImplementationInfo), grouped by both Implementation (stored as
a string) and Interface (stored as a string). Thus given an interface
and implementation, my program needs to get the relevant
ImplementationInfo.
This immediately made me think something like:
map< pair<string,string>, ImplementationInfo >
However, the other need that my program has is to find all
implementations of a given interface or vice versa, which would be
matching "one half" of the key.
I realise that one option would be to store two different maps, one
keyed by interface and one be implementation and do something clever
to make the access nicer, but I was wondering if there was a text-book
example of the data structure I should be using!
Many thanks for any suggestions,
I would just keep a vector of ImplementationInfo objects, each would
have a member-function "string implementation()" and "string
interface()".
If access speed was an issue, I would wrap the vector in a class that
analyzes usage and attempts to keep the ImplementationInfo objects that
are most used at the front of the vector.
If it turned out that one search criteria was more often done than the
other, I would sort the vector based on that criteria.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]