[llvm-commits] [patch] Add a MapVector class

Chandler Carruth chandlerc at google.com
Tue Sep 18 09:27:23 PDT 2012


I think this is fine to go in. I don't want to block further work on the
actual non-determinism. What follows is speculation about future work here:

I'm still not convinced we want to expose the actual DenseMap iteration
ever. I see three options that I think I like better:

1) Don't expose map-style iteration of the keys and values at all.
2) Store vector<pair<const KeyT, ValueT>> as the vector storage, and make
the densemap not even contain the keys.
3) Provide a method on MapVector that returns a vector<pair<const KeyT,
ValueT>> by value, creating it on demand by inserting into a new vector at
the position of the value in the storage vector.

#1 is my favorite, but I'd really have to study the use case(s) you have to
understand if they could be reformulated to work in that model. Might be
worth doing eventually just to understand the requirements.

#2 is appealing in interesting ways. While slower than a traditional
DenseMap, it would have none of the traditional limitations. The DenseMap
could actually be DensMap<unsigned, unsigned> where the key is the
hash_code converted to an unsigned, and the value is the index. It also
provides a natural way to support the pair-based value_type interface
points. However, it would have strictly worse locality than your solution
or #1.

#3 is really just a hack to get the locality of #1 with the interface of
#2, and consequentially making the interface of #2 very costly to use.


Once these issues are sorted out (however they are sorted out) we should
add MapVector to the programmer's guide.

-Chandler


On Tue, Sep 18, 2012 at 8:39 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> > DenseMapInfo only lets me select the key, not values. The value are
> > just default constructed, so I created a wrapper class.
>
> On a discussion on IRC Chandler suggested using insert. The attached
> patch does that.
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120918/554d0ada/attachment.html>


More information about the llvm-commits mailing list