From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22539 invoked by alias); 6 Jul 2005 07:42:57 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22479 invoked by uid 48); 6 Jul 2005 07:42:45 -0000 Date: Wed, 06 Jul 2005 07:42:00 -0000 Message-ID: <20050706074245.22478.qmail@sourceware.org> From: "tneumann at pi3 dot informatik dot uni-mannheim dot de" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050424165745.21193.TazForEver@dlfp.org> References: <20050424165745.21193.TazForEver@dlfp.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libstdc++/21193] provide better std::tr1::hash for std::string and std::wstring X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg00521.txt.bz2 List-Id: ------- 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 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