[Dcmlib] std::map vs std::hash_map

Mathieu Malaterre mathieu.malaterre at kitware.com
Thu Jul 7 03:18:11 CEST 2005


> Wow firecrackers on Bastille Day, I thought you guys just built
> barricades or something. ;-)
> 
> I've been on a bit of wild goose chase WRT map types and hashing. I even
> went so far as to convert my array-based hash map to an STL-compliant
> container with all the required iterators, allocators, algorithms, etc.
> After a solid day of work, my benchmarks show performance about
> equivalent to stdext::hash_map or __gnu_cxx::hash_map. I'm sure most of
> the performance loss is due to use of std::string.
> 
> Of course, avoiding strings as keys altogether can reap significant
> performance gains, but you'll have to get clever with your hash if your
> keys are not densely spaced in their range of values. I have not tested
> it yet, but Google's sparse hash implementation may be worth a look ...
> and you know they care about speed.
> 
> If you can hash on integers, I think you'll want the modulus of the tag
> number by the number of blocks (as opposed to dividing) ... maybe???
> 
> The simplest solution may be using the stock map or hash_map types, but
> keyed by 'const char*' rather than std::string. I think that you can
> safely get away with this since GDCM seems to build the maps in question
> from string literals at compile time. If the map data already exists in
> text segment of the executable, not copying the data into heap space
> (ala std::string) could be a significant optimization.
> 
> This problem still has my interest ... so I'll keep you posted with any
> interesting results or ideas.

Just for reference I recently saw a thread (which I cannot find at the 
moment), where somebody is working on enhancing the hash when using 
string. The only reference I could find is:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21193

The thread must be in gcc, on June or July 2005, but the search engine 
does not seems to work...

Mathieu



More information about the Dcmlib mailing list