简体   繁体   English

c ++使用std :: bitset组合哈希函数

[英]c++ combine hash functions using std::bitset

I recently came across a blog https://worldengineer.me/2015/02/08/combining-container-hashes-with-c14-metaprogramming-cure-for-insomnia-1729/我最近看到一个博客https://worldengineer.me/2015/02/08/combining-container-hashes-with-c14-metaprogramming-cure-for-insomnia-1729/

Where the author combines two hashes by reducing them to their std::bitset representation and concatenating the bitsets and finding the hash of the combined bitset.作者通过将两个散列减少到它们的 std::bitset 表示并连接位集并找到组合位集的散列来组合两个散列。

Granted that probably the motive of the article was to introduce c++ 14 features, i was wondering how good this approach is compared to say, the boost hash_combine function purely on the basis of collision resistance?当然,这篇文章的动机可能是介绍 c++ 14 的特性,我想知道这种方法与纯粹基于抗碰撞性的 boost hash_combine 函数相比有多好?

EDIT:编辑:

By good i mean how does it fare in avoiding collisions compared to the boost libraries' hash_combine method?我的意思是,与 boost 库的 hash_combine 方法相比,它在避免冲突方面的表现如何? And performance wise is it a good option, though i don't think the above approach should take much longer than the hash_combine method.性能方面是一个不错的选择,尽管我认为上述方法不会比 hash_combine 方法花费更长的时间。

I am not doing any serious development with this, just prodding around so just wanted to know the merit of the approach.我没有对此进行任何认真的开发,只是四处游荡,所以只是想知道这种方法的优点。

I would say that我会这样说

  • to hack around and discover new stuff it is fun (do it yourself with std::bitset),四处探索并发现新东西很有趣(用 std::bitset 自己做),
  • but in a serious development prefer using libraries like boost that will hasten your development and avoid errors.但在严肃的开发中,更喜欢使用像 boost 这样的库,这将加速你的开发并避免错误。 Moreover this library is open source and has been developed and read by hundred of professionals.此外,这个库是开源的,已经被数百名专业人士开发和阅读。

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

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