简体   繁体   English

std :: hash算法和大小

[英]std::hash algorithm and size

I'm using C++11 and the std::hash algorithm. 我正在使用C ++ 11和std :: hash算法。 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. 我会假设MD5或SHA,但我不能从互联网中挖掘任何信息。

Also, I'd like to know the actual returned bit-width of the hash, as I have to store it in MySQL. 另外,我想知道散列的实际返回位宽,因为我必须将它存储在MySQL中。

Finally, is it preferable to use std::hash, over say some other library such as crypto++ ? 最后,是否最好使用std :: hash,比如说其他一些库如crypto ++?

The algorithm chosen for std::hash is solely implementation dependant. std::hash选择的算法完全取决于实现。 Probably neither MD5 or SHA are used since they would be performance killers for its purpose. 可能既不使用MD5也不使用SHA,因为它们会成为性能杀手。

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. 大多数实现将比上面提到的要简单得多,因为对于std::hash没有加密要求,而MD5和SHA是为加密目的而开发的。

The requirements of std::hash are much less strict: std::hash要求严格得多:

  1. Accepts a single parameter of type Key . 接受Key类型的单个参数。
  2. Returns a value of type size_t that represents the hash value of the parameter. 返回size_t类型的值,该值表示参数的哈希值。
  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) . 对于两个相等的参数k1k2std::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() . 对于不相等的两个不同参数k1k2std::hash<Key>()(k1) == std::hash<Key>()(k2)的概率应该非常小,接近1.0/std::numeric_limits<size_t>::max()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM