草庐IT

imap_unordered

全部标签

c++ - tbb::concurrent_unordered_map::unsafe_erase 是否会使任何现有的迭代器失效?

我看到tbb::concurrent_unordered_map与std::unordered_map非常接近,同时对于并发是安全的。我也知道unsafe_erase对于insert等不是并发安全的。迭代器文档还声明任何现有的迭代器对于insert仍然有效,查找等问题是,unsafe_erase是否会使除被要求删除的迭代器之外的任何其他迭代器失效?std::unordered_map和std::map当然有这种行为,但它没有在任何地方的concurrent_unordered_map文档中指定。 最佳答案 tbb::unsafe_e

c++ - 分配时 unordered_map 更改的顺序

我对这种行为很好奇。我发现分配unordered_map会更改无序映射的内部顺序,而无需任何插入/删除操作:unordered_mapm1;unordered_mapm2;unordered_mapm3;m1[2]="john";m1[4]="sarah";m1[1]="mark";m2=m1;m3=m2;for(autoit=m1.begin();it!=m1.end();++it){coutsecondsecondsecond输出:marksarahjohnjohnsarahmarkmarksarahjohn我知道unordered_map没有维护任何特定的顺序,因为它内部是一个哈

c++ - std::unordered_map<int,float> 是否仍然需要散列整数才能得到值?

我想知道是否std::unordered_map仍然必须对给定的整数进行哈希处理才能得到该值,或者直接使用它。我需要每秒多次快速执行此操作,如std::hash不能保证是身份函数,我将如何重新定义它?(显然不使用STL并编写我自己的容器是可能的,但我怀疑我编写的容器是否会更有效率(可能慢得多,慢得多))。谢谢! 最佳答案 Iwouldliketoknowwhetherstd::unordered_mapstillhastohashthegiveninteger是的。Ineedtoperformthisoperationveryfas

c++ - boost::unordered_map 中的迭代器失效

我正在使用boost::unordered_map如下typedefboost::shared_ptrPtrWriter;typedefstd::listPtrList;boost::unordered_map,PtrList>MapMapinstrMap;现在我正在循环中对PtrList类型的列表进行一些更改for(autoit=instrMap.begin();it!=instrMap.end();++it){autokey=it->first();autolist&=it->second();//Makesomechangetoanelementinlistif(list.emp

c++ - 键不存在时 unordered_multimap::bucket() 的返回值?

当key不存在时,unordered_multimap::bucket(key)是什么应该回来吗?引用资料说它应该返回包含键的桶的桶号,但没有说明当unordered_multimap中不存在该键时会发生什么。Itrieditmyself但我得到的结果不正确:std::unordered_multimapm={{"jack","foo"},{"jill","bar"}};std::cout输出是:jackisinbucket3jillisinbucket4bjarneisinbucket4这是否意味着我必须使用unordered_multimap::count(key)==0来捕获不存

c++ - 当 wordCount 中不存在键时,我应该对 unordered_map<string, int> 使用++wordCount[key] 吗?

见下面的代码:unordered_mapwordCount;for(stringword:words)++wordCount[word];问题:当wordCount中不存在word时,是否可以使用++wordCount[word];?我总是看到有人这样使用,但我不太确定。说明here说:Ifkdoesnotmatchthekeyofanyelementinthecontainer,thefunctioninsertsanewelementwiththatkeyandreturnsareferencetoitsmappedvalue.Noticethatthisalwaysincreas

c++ - 在 std::unordered_map 中使用模板化键

我不明白为什么我的编译器不接受下面的代码#include#includetemplateusingM=std::unordered_set;templateusingD=M;templateusingDM=std::unordered_map::const_iterator//Problem,typenameD::const_iterator>;//Problemintmain(intargc,char**argv){Dd;Mm;DMdm;//Problem}编译命令是clang++-std=c++14test.cpp-otest编译器错误消息摘录是/usr/bin/../lib/gc

c++ - 奇怪的迭代器行为 + unordered_set 的段错误

我有一个类有一个unordered_set成员如下:我有以下类定义,后面是它的常规构造函数和复制构造函数,以及一些其他修改集合的函数(删除了不相关的代码段,因为类很长):#include#include#includeclassHexBoard{public:HexBoard(intn);HexBoard(constHexBoard&obj);std::unordered_setemptyPositions();private:std::unordered_setempty_positions;};HexBoard::HexBoard(intn){for(inti=0;i=nempty

c++ - boost::unordered_map -- 需要指定自定义哈希函数来散列 std::set<int> 吗?

我想使用boost::unordered_map,其中key是std::set.由于一组整数不是内置类型,我假设我必须提供我自己的散列函数(或者,更确切地说,我正在考虑使用boost'shash_range)。但是,现在我尝试像这样初始化散列映射,既不提供散列函数也不提供相等谓词——而且gcc没有提示。这里发生了什么?boost是否足够聪明,可以自行散列所有STL容器?这会比我使用自定义哈希函数慢吗?使用boost::hash_range怎么样??提前致谢。 最佳答案 根据theBoostdocumentation:thedefau

c++ - unordered_map 如何导致 sigsegv

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭10年前。编辑:已解决,我知道怎么做,但我不明白为什么。我改变了variables来自的声明tr1::unordered_mapvariables;到unordered_mapvariables;它工作正常。如果您知道原因,请将其写在答案中。我有一个非常大的程序,所以我不知道应该把哪个代码放在这里。有抽象类,继承派生类。摘要有unordered_map(模板)作为私有(private)成员和公共(publ