使用 unordered_set;或 unordered_set?
如果我们使用 unordered_set
(T
是自定义类型,而不是简单类型),很可能我们需要定义自定义 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论