Multimap query

V

Vandana

Hello All,

I have a question regarding multimaps. The reason I am using
multimap is because for a key, there
can be more than 1 value. The value I am storing is a simple struct
which has the following form.

struct myStruct {
string name;
int val;
}

So the multimap defintion looks like this
typedef multimap<int, myStruct> mymultimap;

In the program, I populate 2 of these multimaps & I have to compare
them.

For each key, I must find out the difference in their values, whether
both have same values.
My question is: what is the most efficient way to compare multimaps.
Am I correct about using a multimap for my problem?

Thanks for your time & help.
Vandana
 
V

Victor Bazarov

[..] The reason I am using
multimap is because for a key, there
can be more than 1 value. The value I am storing is a simple struct
which has the following form.

struct myStruct {
string name;
int val;
}

So the multimap defintion looks like this
typedef multimap<int, myStruct> mymultimap;

In the program, I populate 2 of these multimaps& I have to compare
them.

For each key, I must find out the difference in their values, whether
both have same values.

What happens if one multimap contains more values for a particular key
than the other multimap?

Do you need to compare the values *of* the keys or the values *that
correspond to* the keys? IOW, do you need to compare 'int' or do you
need to compare 'myStruct'? Your 'myStruct' type does not contain any
comparison capabilities (at least you didn't show them).
My question is: what is the most efficient way to compare multimaps.

<cheapshot>
My question is: why aren't you using a question mark to end a question?
</cheapshot>

Seriously, though, have you tried simply to enumerate elements of one
and the other and just compare the values? I think an algorithm that
computes a set difference (or a union) basically enumerates both sets
and compares the elements. Your comparison algorithm looks a lot like a
calculation of a "set difference" using those multimaps.

You need to loop using iterators until either of those is at the end,
and (a) compare each iterator's dereferenced value (which should be a
'key/value' pair from that map), and if they are equal, move onto next,
if not, indicate that they are not.

Now, you didn't specify, and it's unclear what "the difference in their
values" might mean. What's "a difference between two 'myStruct' values"
in your definition?
Am I correct about using a multimap for my problem?

I don't know. Which problem is that?

V
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top