STL Hash Functions
Does the STL have any Hash functions available, that are exposed publicly?
I know that there are some non-standard implementati开发者_JS百科ons that use hash values (such as boost::hash_map), and MSVC8 implements a version of the hash_map/hash_set/etc.
But are there any Hash Functions that are defined in the C++98 STL?
If not, what are the best non-C++98 sources of a reliable hash function?
Order of preferred sources (from most acceptable to least): Boost, C++0x standard STL, TR1, other 3rd party.
to summarize:
- The STL has hash functions
- The C++98 standard library does not
- The C++ TR1 has hash functions (
6.3.3[tr.unord.hash]
) - boost has hash functions
- The C++11 standard library has hash functions (
20.8.12[unord.hash]
)
And all of them are designed for hashed associative containers, not for cryptography.
I guess you're looking for hash functions for hash tables, not for cryptography, correct?
In that case, what about boost::hash?
The documentation says it's compatible with the TR1 hash, which should become part of the upcoming C++0x standard. That means it's probably already found in quite a few compilers.
For cryptographic hashes, there seems to be a SHA-1 implementation in Boost, but the way to go if you need them heavyweight is to use a dedicated library, such as Crypto++.
The choice of Hash function ideally depends on your use for the results. I suspect this may partly be due to the idea "one size does not fit all".
精彩评论