This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug libstdc++/21193] provide better std::tr1::hash for std::string and std::wstring


------- Additional Comments From tneumann at pi3 dot informatik dot uni-mannheim dot de  2005-07-06 07:42 -------
How about using a union-cast to hash floating point numbers? Something like this

unsigned hash(double v) {
   union { double a; unsigned long long b; } tmp;
   tmp.a=v; return tmp.b^(tmp.b>>32);
}

The code is only a sketch (assumes 32bit unsigned etc.) but should produce much 
better results than the current hash function. It should also avoid the problems 
with unordered_set<double> mentioned on the mailing list.
The main disadvantage is that it forces memory access, which is somewhat slow.
Another problem is that the resulting hash value is not portable, but this is 
probably ok.


-- 


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


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