我想在项目中使用unordered_set
。
然而,它的文档要么不完整,要么只是技术参考,没有示例。
有没有人可以提供处理它的在线资源链接? 书籍也受欢迎,最好是免费的。 谷歌搜索没有返回任何有价值的结果。
谢谢!
我想在项目中使用unordered_set
。
然而,它的文档要么不完整,要么只是技术参考,没有示例。
有没有人可以提供处理它的在线资源链接? 书籍也受欢迎,最好是免费的。 谷歌搜索没有返回任何有价值的结果。
谢谢!
最常见用例的代码:
#include <boost/unordered_set.hpp>
using boost::unordered_set;
using std::string;
using std::cout;
using std::endl;
int main (void)
{
// Initialize set
unordered_set<string> s;
s.insert("red");
s.insert("green");
s.insert("blue");
// Search for membership
if(s.find("red") != s.end())
cout << "found red" << endl;
if(s.find("purple") != s.end())
cout << "found purple" << endl;
if(s.find("blue") != s.end())
cout << "found blue" << endl;
return 0;
}
输出
found red
found blue
更多信息
http://www.cplusplus.com/reference/unordered_set/unordered_set/find/
std::set
完全相同,因此关于它的文档很少。只需查找 std::set
的示例,然后将其替换为 std::unordered_set
即可。我建议您使用与std::set
或其他容器相同的访问方法,http://www.boost.org/doc/libs/1_37_0/doc/html/unordered.html也提出了类似的建议。
unordered_set
还有可能变慢的方式,例如:https://svn.boost.org/trac/boost/ticket/3693 - John Zwinckstd::set
完全相同。 - Billy ONeal