草庐IT

unordered-multimap

全部标签

c++ - 是什么导致 clang 找不到 unordered_map header ?

我正在尝试使用Clang++编译我在网上找到的程序。Makefile生成此命令:clang++-c-archx86_64-msse3-std=c++11-stdlib=libstdc++-Wno-missing-field-initializers-Wno-missing-prototypes-Wreturn-type-Wno-non-virtual-dtor-Wno-exit-time-destructors-Wformat-Wmissing-braces-Wparentheses-Wno-switch-Wunused-function-Wunused-label-Wno-unuse

c++ - 避免在 std::map/std::unordered_map 中使用 std::string 键查找临时对象

这个问题在这里已经有了答案:Avoidingkeyconstructionforstd::map::find()(4个答案)关闭8年前。考虑以下代码:std::mapm1;autoi=m1.find("foo");constchar*key=...autoj=m1.find(key);这将为每次map查找创建一个临时的std::string对象。避免它的规范方法是什么?

c++ - unordered_set::remove_if(): C3892: 无法分配给常量变量

我有这样的代码:unordered_setoutput;...autorequiredType=variables.at(arg.value);autoend=remove_if(output.begin(),output.end(),[&](AttrValuex){return!matchingOutputType(requiredType,ast->getNodeType(ast->getNodeKeyAttribute(x)));});//queryevaluator_getcandidatelist.cpp(179)output.erase(end);错误在代码的第4行。所以我

c++ - 如何判断两个 LARGE unordered_map 是否相等?

给定两个大的unordered_map,比如map_a,map_b。如何有效判断map_a和map_b的信息相同?例如,如果map_a是{'a':3,'b':2}并且map_b是{'a':3,'b':2}那么他们是一样的。也就是说,对于map_a中的每个键k,map_a[k]=map_b[k]。我的问题是如何有效地决定这个问题。我知道最糟糕的时间是O(max{map_a.size(),map_b.size()})。但是有一些观察可以快速确定map_a不等同于map_b。例如,map_a.size()!=map_b.size()。还有其他观察结果吗?我们可以使用bucket_count(

c++ - 以引用为值的 unordered_map

具有值类型为引用C++11的unordered_map是否合法?例如std::unordered_map我已经设法让它与VS2013一起编译,但是我不确定它是否应该这样做,因为它会导致一些奇怪的运行时错误。例如vectorsubscriptoutofrange尝试erase时抛出一个元素。一些谷歌搜索结果发现你不能有一个引用vector,但我找不到任何关于unordered_map的信息。更新进一步的实验表明vectorsubscriptoutofrange与引用的unordered_map无关,因为它是我代码中的错误。 最佳答案

c++ - clear() 是否影响 std::unordered_set 的桶计数?

有很多answers使用std::vector,但是std::unordered_set呢?我真正的问题(密切相关)是这样的;如果我事先保留我知道的合理大小,通过在每次使用前清除它来重用相同的无序集是否有效? 最佳答案 正式的回答是:这取决于实现。非正式的回答是:unordered_set里面有一个(某种)桶数组,而且很可能实现是和vector一致的,所以这个数组不会当clear()被调用时被删除。所以调用clear()很可能会带来一些好处。 关于c++-clear()是否影响std::

c++ - 如何unordered_set<tuple<int,int>>?

我在构建unordeed_set>时遇到了奇怪的问题.我试过VC++8、gcc3.2、gcc4.3,结果都是一样的。我不知道代码有什么问题,以下是我的代码:#include#include//Forunorderedcontainer,thedeclarationofoperator==#includeusingnamespacestd;usingnamespaceboost;//defineofthehash_valuefuncitonfortuplesize_thash_value(tupleconst&t){returnget(t)*10+get(t);}intmain(){un

c++ - 如何散列 unordered_map?

boost::hash具有适用于大多数内置类型(包括容器)的哈希函数。但如boost::hash_rangefunctiondescription中所述,范围的哈希算法issensitivetotheorderoftheelementssoitwouldn'tbeappropriatetousethiswithanunorderedcontainer因此,std::unordered_map和boost::unordered_map都没有boost::hash特化。问题是:是否有一种“简单有效”的方法来散列unordered_map而无需从头开始重新实现散列算法?

c++ - 与 std::unordered_map 的数据竞争,尽管使用互斥锁定插入

我有一个C++11程序,它执行一些计算并使用std::unordered_map来缓存这些计算的结果。该程序使用多个线程,它们使用共享的unordered_map来存储和共享计算结果。基于我对unordered_map和STL容器规范的阅读,以及unordered_mapthreadsafety,似乎一个unordered_map,被多个线程共享,一次可以处理一个线程写入,但是一次可以处理多个读取器。因此,我使用std::mutex来包装我对map的insert()调用,这样最多只有一个线程插入时间。但是,我的find()调用没有互斥锁,因为从我的阅读来看,似乎许多线程应该能够同时读取

c++ - 具有相同散列值的值是否在同一个 std::unordered_map 桶中?

如果std::unordered_map的两个键具有相同的哈希值,标准是否保证它们将进入同一个桶?根据模板相等谓词,我们假设键不相等,它们仅具有相同的哈希值。奖励问题:如果相同的散列并不意味着相同的桶,那么能够单独遍历桶的目的是什么? 最佳答案 具有相同哈希值的对象被无序关联容器放入同一个桶中。因此,两个相等的对象必须具有相同的哈希值。23.2.5第8段:Theelementsofanunorderedassociativecontainerareorganizedintobuckets.Keyswiththesamehashcod