[Interest] QMap operator<() overload.

Torgeir Lilleskog torgeir.lilleskog at gmail.com
Wed Feb 25 15:45:12 CET 2015


I like this talk by Chandler Carruth:
https://www.youtube.com/watch?v=fHNmRkzxHWs

He says something along the lines of "I don't think I've ever seen a
problem for which std::map is the right data structure"
QMap is the same type of data structure as std::map.

If your map is small and not expected to scale and you are comfortable with
the performance of a map for this data it will be OK. Measure if in doubt
:-)

I think it is really good for programmers to be aware of the cost of using
data structures like linked lists/maps/hashes.
The costs/tradeoffs have really changed the last 10+ years or so. What used
to be a good data structure in the 90s may have absolutely terrible
performance today. And it is not just some percentage differences,
sometimes one may see 10x-50x performance difference from a change in data
layout alone.

Best regards,
- Torgeir

On Wed, Feb 25, 2015 at 2:19 PM, Koehne Kai <Kai.Koehne at theqtcompany.com>
wrote:

>
>
> > -----Original Message-----
> > From: interest-bounces+kai.koehne=theqtcompany.com at qt-project.org
> > [...]
> > Could you elaborate a little on your comment, and on for which use cases
> > QMap might not be the "right" abstraction?
> >
> > I've always thought that maps (and hash-maps, e.g. std::unordered_map)
> > were the right tool when you want to look up a value using a key.  Are
> there
> > pitfalls in this use case?
>
> As usual with performance, it highly depends on how you use it ... Anyhow,
> this was recently discussed on the development at qt-project.org mailing ist:
>
> http://permalink.gmane.org/gmane.comp.lib.qt.devel/20044
>
> > Or are there other use cases where you often see people using maps when
> > something else would be more efficient?
>
> Citing from the above:
>
> " In the vast majority of cases, a sorted vector is much faster, due to
> locality-of-reference. A RB-tree is optimized for wildly mixing insertions,
> lookups, and removals. When you can batch updates and separate them from
> lookups, time-wise, then a sorted vector is usually preferrable."
>
> If in doubt (and it matters), measure :)
>
> Regards
>
> Kai
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150225/1374a7f2/attachment.html>


More information about the Interest mailing list