草庐IT

unordered-multimap

全部标签

c++ - 不完整类型 struct std::hash 与 unordered_map 的无效使用,其中 std::pair of enum class 作为键

我想使用unordered_map,std::uint8_t>用于管理一些像素图格式。这里是最少的代码:#include#include#include#include#includeenumclassPNM:std::uint8_t{PBM,PGM,PPM};enumclassFormat:bool{BIN,ASCII};structpair_hash{public:templatestd::size_toperator()(conststd::pair&x)const{returnstd::hash()(x.first)^std::hash()(x.second);}};intma

c++ - 如何迭代 unordered_set 中的无序对?

在unordered_set中迭代无序元素对的简洁方法是什么?(因此顺序无关紧要,元素应该不同)e.g.{1,2,3}=>(1,2)(2,3)(1,3)我最初的尝试是这样的for(i=0;i但是对于迭代器来说这不是super方便。 最佳答案 这应该有效,给定一个std::unordered_sets:autoset_end=s.end();for(autoai=s.begin();ai!=set_end;++ai){for(autobi=std::next(ai);bi!=set_end;++bi){//*ai,*bi}}这基本上是

c++ - unordered_map 具有三个元素

我试图在unordered_map中包含三个元素。我试过下面的代码#include#include#include#includetypedefboost::unordered_map>mymap;mymapm;intmain(){//std::unordered_map>m;m.insert({3,std::make_pair(1,1)});m.insert({4,std::make_pair(5,1)});for(auto&x:m)std::cout但是我在打印语句中遇到了很多错误,比如‘std::pair’isnotderivedfrom‘conststd::__cxx11::b

c++ - 如何使用 const 键复制 unordered_map?

简单代码:#includeintmain(){std::unordered_mapm;std::unordered_mapm1=m;}产生复杂的编译错误信息:ErrorC2280'std::hash::hash(void)':attemptingtoreferenceadeletedfunction在其内部基本上说unordered_map并不期望key是常量附言:我读过answer对于类似的问题:Theassociativecontainersonlyexposethe(key,value)pairasstd::pair,sotheadditionalconstonthekeytyp

c++ - 为什么 vector 比 unordered_map 快?

我正在LeetCode上解决一个问题,但还没有人能够解释我的问题。问题是这样的:给定一个任意的赎金票据字符串和另一个包含来自所有杂志的字母的字符串,编写一个函数,如果赎金票据可以从杂志中构造出来,该函数将返回true;否则,它将返回false。杂志字符串中的每个字母只能在您的赎金记录中使用一次。注意:您可能会假设这两个字符串都只包含小写字母。canConstruct("a","b")->falsecanConstruct("aa","ab")->falsecanConstruct("aa","aab")->true我的代码(耗时32毫秒):classSolution{public:bo

c++ - Eigen::aligned_allocator 因 std::unordered_multimap 而失败

我正在尝试在XCode6中编译这段代码:std::unordered_multimap,std::equal_to,Eigen::aligned_allocator>>trackingFailed;它失败了:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/unordered_map:1461:5:Static_assertfailed"Invalidallocator::value_type"Eigen3.2.2还需要用aligned_al

c++ - unordered_map - {{key,value},{key,value}} 语法无效

我正在尝试编译thecodetakenfromhere//constructingunordered_maps#include#include#includetypedefstd::unordered_mapstringmap;stringmapmerge(stringmapa,stringmapb){stringmaptemp(a);temp.insert(b.begin(),b.end());returntemp;}intmain(){stringmapfirst;//emptystringmapsecond({{"apple","red"},{"lemon","yellow"}}

c++ - 我们什么时候应该为 `std::unordered_set` 提供我们自己的哈希函数

当我编译下面的代码时,我看到了与Hash相关的错误。intF_no_meaningA(unordered_set>&setVec,vector&vec){setVec.insert(vec);return1;}intmain(){vectorW{2,3,7};unordered_set>setVec;}$g++--versiong++(Ubuntu/Linaro4.6.3-1ubuntu5)4.6.3$g++$1.cpp-o$1-g-Wall-Weffc++-pedantic-std=c++0x/tmp/ccCQFQ4N.o:Infunction`std::__detail::_Has

c++ - 在 std::unordered_map 中查找对应于相同值的所有键

我有一个unordered_map看起来像这样:std::unordered_maptheMap2={{1,"a"},{2,"b"},{3,"c"},{4,"a"}};我想找到所有具有相同值的键让我们说“a”。除了明显的方式之外的任何建议:std::vectorarrKeys;std::stringvalue="a";for(constauto&element:theMap)if(element.second==value)arrKeys.push_back(element.first); 最佳答案 我认为“显而易见”的方式非常好:

c++ - 在 gdb 上漂亮地打印 boost::unordered_map

最近我开始在我的系统上使用优秀的boost::unordered_map,但有一个缺点:我不知道如何检查它的内容。在gdb上打印它给了我一个table_和一个buckets_,但还没有找到项目在哪里。有人知道这件事吗? 最佳答案 对于那些想要打印机的人,我已经设法制造了一台。这是代码:classBoostUnorderedMapPrinter:"printsaboost::unordered_map"class_iterator:def__init__(self,fields):type_1=fields.val.type.temp