9得票2回答
有没有默认的哈希函数可以用于自定义类的unordered_set?

我第一次使用std::unordered_set,关于哈希函数我有一个问题。据我所知,如果您不指定哈希函数,它将默认为std::hash<Key>。 我在我的一个类中有一个名为mySet的成员: typedef std::unordered_set<MyClass>...

33得票2回答
使用自定义哈希函数向无序集合中插入元素

我有以下代码用于创建一个 unordered_set<Interval>。这段代码可以编译通过。struct Interval { unsigned int begin; unsigned int end; bool updated; //true if conca...

12得票2回答
unordered_set<int> 的查找方法的时间复杂度是多少?

find方法在unordered_set&lt;int&gt;中的时间复杂度是什么? 同时,是否可以更改哈希函数?

20得票3回答
如何使用带有自定义结构体的unordered_set?

我想要使用一个自定义的struct和unordered_set。在我的情况下,这个自定义的struct代表着欧几里得平面上的二维点。我知道需要定义一个哈希函数和比较运算符,而且我已经按照下面代码的方式进行了定义:struct Point { int X; int Y; ...

7得票2回答
如何统计 C++ 中的 unordered_set 中的碰撞次数

我希望能计算一些关于我的哈希函数的统计数据(如最大/平均冲突次数)。我编写了一个虚拟的哈希函数(将所有键映射到1),并等待着看到最大/平均冲突次数等于键的数量。但是对于不同的函数,我得到了相同的数字。有人能解释一下吗? 代码: #include &lt;iostream&gt; #inclu...

62得票5回答
无序映射/集合中元组的通用哈希函数

为什么std::unordered_map&lt;tuple&lt;int, int&gt;, string&gt;不能直接使用?定义tuple&lt;int, int&gt;的哈希函数很麻烦。template&lt;&gt; struct do_hash&lt;tuple&lt;int, i...

24得票1回答
我该如何使用unordered_set?

我想要这样定义一个无序集合:unordered_set&lt;Point&gt; m_Points; 编译时,我收到以下错误信息: C++标准没有为此类型提供哈希。 Point类:class Point{ private: int x, y; pub...

9得票4回答
std::unordered_set是否是连续的(像std::vector一样)?

我正在std::unordered_set中存储指针。我这样做是因为我不想有任何重复项(我在集合中删除指针,所以如果有重复项,我将尝试删除已经删除的指针)。我频繁地遍历这些集合,由于我知道std::vector是最快的容器(连续内存)用于循环,所以我想知道std::unordered_set是...

8得票1回答
如何在只有 const shared_ptr 的 unordered_set 中查找一个 shared_ptr?

我有一个无序集合unordered_set&lt;shared_ptr&lt;T&gt;&gt; us,我想知道针k是否在us中,但是k的类型为shared_ptr&lt;T const&gt;,所以unordered_set&lt;shared_ptr&lt;T&gt;&gt;::find会...

56得票3回答
如何在C++中遍历无序集合?

假设我有一个无序集合unordered_set&lt;int&gt; my_set; myset.insert(1); myset.insert(2); myset.insert(3); 如何遍历它?我不需要按任何顺序遍历-只要能够访问每个元素就可以了。我尝试过for (int i = 0; ...