This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/21193] provide better std::tr1::hash for std::string and std::wstring
- From: "tneumann at pi3 dot informatik dot uni-mannheim dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jul 2005 07:42:45 -0000
- Subject: [Bug libstdc++/21193] provide better std::tr1::hash for std::string and std::wstring
- References: <20050424165745.21193.TazForEver@dlfp.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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