1

I was looking at storing a set of values in a map, with an int as a key: -

QMap<int, QSet<QString> > setOfValues;

While reading the documentation, I noticed that QMap provides the insertMulti function, to allow inserting multiple values for the same key.

Ignoring QMultimap, since this is just a convenience wrapper around QMap::insertMulti, would there be any advantage of using the insertMulti function of QMap, rather than a map of a set, as above?

László Papp
  • 51,870
  • 39
  • 111
  • 135
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • The main advantage is simplicity in my opinion. You would use the insertMulti/MultiMap for the use case it was invented rather than putting two different use cases put together. Also the underlying algorithm changes, and hence the complexity may change, too. Whether that matters, it depends on the operations you wish to achieve. Perhaps, you are more interested in the algorithm complexity? Then, it is better to know more about the use case how this data structure is supposed to be used. – László Papp Apr 11 '14 at 20:49
  • Thanks @LaszloPapp, actually, I'd disagree with insertMulti adding simplicity, as it completely changes the purpose of a map by allowing it to also be a multimap and it would be easy for someone to accidentally use the standard insert by mistake. However, the QMultimap class is clear in its design. Anyhow, it is the underlying implementation that I'm referring to as to whether there is an advantage in using insertMulti over the map of a set. – TheDarkKnight Apr 23 '14 at 08:20

0 Answers0