home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,864 of 33,346   
   James Kanze to Francis Glassborow   
   Re: default hash performance of unordere   
   19 Feb 13 16:41:38   
   
   From: james.kanze@googlemail.com   
      
   On Thursday, 14 February 2013 17:43:48 UTC, Francis Glassborow  wrote:   
   > On 14/02/2013 00:14, TS wrote:   
      
   > > I just noticed that C++0x includes unordered_map/set based on hash table.   
   > > They allow users to specify their own hash and compare functions. However,   
   > > it seems that they also include some default implementations of those   
   > > functions, as compilers do not complain even if I don't provide them.   
      
   > > My questions are   
   > > 1. How are the performance of the default hash functions?   
   > > 2. If I use a class defined by myself as a key, how does the default   
   > > hash function know how to hash my type?   
   > > 3. Have the default functions been optimized for certain built-in types?   
   > > If so, what are they?   
      
   > The answers to questions 1 & 3 are dependant on the implementation. As   
   > for question 2, I think that all that is required is something that   
   > works (e.g. it could simply hash on the raw bytes)   
      
   Hashing on the raw bytes won't work.  Think of just about any   
   container class (where the raw bytes are a pointer), or any   
   class which contains a floating point (where the raw bytes of   
   -0.0 and 0.0 are different).   
      
   IIUC, there is no generic implementation of the template, only   
   specializations.  If the specialization isn't specified in the   
   standard, you have to provide one.  (It is, IMHO, the only thing   
   that makes sense.)   
      
   With regards to 1 and 3, those are quality of implementation   
   issues.  I know that I can (and have) artificially constructed   
   sets of data which lead to many collisions with the   
   implementation g++ provides for std::string, and such data sets   
   might occur in some special applications, but the basic   
   algorithm they use is sound for most cases, and very fast.   
   I wouldn't worry about it unless you have some very, very   
   particular sort of data.   
      
   --   
   James   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca