std::hash algorithm and size

I'm using C++11 and the std::hash algorithm. I was wondering, what actual hash implementation is used? I would assume MD5 or SHA, but I can't dig any info from the internets.

Also, I'd like to know the actual returned bit-width of the hash, as I have to store it in MySQL.

Finally, is it preferable to use std::hash, over say some other library such as crypto++ ?

Answers


The algorithm chosen for std::hash is solely implementation dependant. Probably neither MD5 or SHA are used since they would be performance killers for its purpose.

Most implementation will be much more trivial than the above mentioned since there is no cryptographic requirement for std::hash while MD5 and SHA have been developed for cryptographic purposes.

The requirements of std::hash are much less strict:

  1. Accepts a single parameter of type Key.
  2. Returns a value of type size_t that represents the hash value of the parameter.
  3. Does not throw exceptions when called.
  4. For two parameters k1 and k2 that are equal, std::hash<Key>()(k1) == std::hash<Key>()(k2).
  5. For two different parameters k1 and k2 that are not equal, the probability that std::hash<Key>()(k1) == std::hash<Key>()(k2) should be very small, approaching 1.0/std::numeric_limits<size_t>::max().

Need Your Help

In Common Lisp why does the macro OR use a gensym, but not AND?

macros lisp common-lisp sbcl

In Common Lisp (SBCL 1.0.58) why does the macro OR use a gensym, but not AND?

Sharepoint Workflow Development (2 part question)

visual-studio sharepoint workflow

I'm trying to develop some SharePoint workflows for the company I work for, and I'm not too familiar with the ins and outs of the technology. Normally when I want to familiarize myself with someth...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.