Boost - unordered_set教程/ examples/ANYTHING?

F. *_* P. 9 c++ boost stl unordered-set c++11

我想unordered_set在一个项目中使用.

但是,它的文档要么不完整,要么只是技术参考,没有示例.

任何人都可以提供与处理它的在线资源的链接吗?书籍也欢迎,最好免费.Google搜索没有带来任何价值.

谢谢!

Chr*_*ord 9

最常见用例的代码:

#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;
}
Run Code Online (Sandbox Code Playgroud)

产量

found red
found blue
Run Code Online (Sandbox Code Playgroud)

更多信息

http://www.cplusplus.com/reference/unordered_set/unordered_set/find/


Bil*_*eal 7

关于它的文档很少,因为它的行为完全相同std::set,除了它需要散列和等于函数而不是比较函数.只需查看示例std::set,并替换它们,std::unordered_set你应该没问题.

如果您需要编写散列函数,则文档中有一些示例,即示例.