This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: hash_multimap


    That is contrary to what one would expect, isn't it? I have not tried using
SGI's hash_map or multi_map but I'll give you a couple of "perhaps" that you might
want to evaluate. The primary difference between the map and hash_map (in terms of
your contained class type) is that the standard map uses the less<> function whereas
hash_map uses a hash() method. I would write some code that iterates these
operations for the type that I'm holding in my map and see if one happens to be
faster than the other. If that is the case then you may consider overloading the
hash() method for your type.

    The second "perhaps" is that of handling collisions. The implementation of the
hash table may not be efficient at this whereas the Red-Black Tree (which is how
most maps and multi_maps are implemented) may not lose too much efficiency in
dealing with this additional functionality. If the less<> vs. hash() idea doesn't
get you fixed then do everything you can to figure out a way for your keys to be
unique so you don't need a multi_* container or implement the hash table yourself
and find a more efficient collision handling mechanism.

    Please post your results here when you check it out because I'm about to delve
into code that will require the use of these very containers and would love to know
what you discover.

        regards,

            Ben Scherrey

PS: Third "perhaps" - check (i.e. explicitly specify) your allocators! Could be a
memory management problem.

SEGV wrote:

> <snip>
> I thought I'd use a hash_multimap, even though it isn't Standard C++, to speed
> things up with more items. I found the hashed associative containers in my C++
> headers, as supplied by SGI.
>
> However, I found things quite slower with the hashed containers, which is not
> what I would have expected. Below are four measurements, with 50 then 100 items.

> <snip>
>
> Why is this? Is it because the SGI headers are not maintained or inferior? I am
> confused. Worse, I needed better performance and was hoping the hashed
> containers were my ace in the hole!

<snip>



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]