使用 unordered_set;或 unordered_set

发布于 2025-01-16 06:59:35 字数 586 浏览 2 评论 0原文

如果我们使用 unordered_setT 是自定义类型,而不是简单类型),很可能我们需要定义自定义 operator==和 hasher,如果我们在一个大项目中有很多不同的 T ,这有点麻烦。此外,如何选择一个好的哈希函数是一个大问题。

但是如果我们使用unordered_set(包括智能指针),我们可以省略这些定义。特别是我发现在rocksdb和mysql-server代码库中,使用了很多unordered_set而不是unordered_set,而在mongodb和scylladb中,很多unordered_set 已定义。这种情况给我的印象是rocksdb开发者似乎有意避免使用unordered_set

所以我有点困惑何时使用 unordered_set 以及何时使用 unorderd_set

If we use unordered_set<T> (T is custom type, not simple type), it's quite likely that we need define custom operator== and hasher, which is kind of cumbersome if we have lots of different T in a big project. Furthermore how to choose a good hash function is a big issue.

But if we use unordered_set<T*> (including smart pointer), we can omit those definitions. Especially I find in rocksdb and mysql-server codebase, lots of unordered_set<T*> are used instead of unordered_set<T>, whereas in mongodb and scylladb, lots of unordered_set<T> defined. This situation gives me impression that rocksdb developers seems intentionally to avoid using unordered_set<T> ?

So I'm a little confused when to use unordered_set<T> and when use unorderd_set<T*> ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文