C ++中unordered_map / set有更快的散列函数吗? [英] Are there faster hash functions for unordered_map/set in C++?

查看:155
本文介绍了C ++中unordered_map / set有更快的散列函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认函数来自std :: hash。我想知道是否有更好的散列函数来节省计算时间?整数键以及字符串键。



我试过Google的City Hash,它的整数和字符串键都有,但它的性能比std :: hash要差一些。

解决方案

::哈希函数在性能方面已经很好。我认为你应该尝试开源的哈希函数。



检查一下 https://github.com/Cyan4973/xxHash 。我引用它的描述:xxHash是一种非常快速的哈希算法,运行在RAM速度极限,它成功地完成了SMHasher测试套件,用于评估散列函数的碰撞,离散和随机性质量。所有平台(小/大端)



另外这个线程这个网站的其他问题:的快速跨平台C / C ++哈希库。 FNV,Jenkins和MurmurHash被认为是快速的。

Default function is from std::hash. I wonder if there are better hash functions for saving computational time? for integer keys as well as string keys.

I tried City Hash from Google for both integer and string keys, but its performance is a little worse than std::hash.

解决方案

std::hash functions are already good in performance. I think you should try open source hash functions.

Check this out https://github.com/Cyan4973/xxHash. I quote from its description: "xxHash is an Extremely fast Hash algorithm, running at RAM speed limits. It successfully completes the SMHasher test suite which evaluates collision, dispersion and randomness qualities of hash functions. Code is highly portable, and hashes are identical on all platforms (little / big endian)."

Also this thread from another question on this site: Fast Cross-Platform C/C++ Hashing Library. FNV, Jenkins and MurmurHash are known to be fast.

这篇关于C ++中unordered_map / set有更快的散列函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆