草庐IT

unordered-multiset

全部标签

c++ - 如果我只想指定一个哈希函数,我应该将什么传递给 unordered_map 的存储桶计数参数?

C++11的unordered_map的默认构造函数如下所示:explicitunordered_map(size_typebucket_count=/*implementation-defined*/,consthasher&hash=hasher(),constkey_equal&equal=key_equal(),constallocator_type&alloc=allocator_type());我想创建一个带有自定义哈希函数的unordered_map,但它是构造函数的第二个参数。我应该使用多少桶数?我可以使用一个神奇的值来告诉容器自己决定吗?否则,是否有一种启发式方法可以

c++ - 如果我只想指定一个哈希函数,我应该将什么传递给 unordered_map 的存储桶计数参数?

C++11的unordered_map的默认构造函数如下所示:explicitunordered_map(size_typebucket_count=/*implementation-defined*/,consthasher&hash=hasher(),constkey_equal&equal=key_equal(),constallocator_type&alloc=allocator_type());我想创建一个带有自定义哈希函数的unordered_map,但它是构造函数的第二个参数。我应该使用多少桶数?我可以使用一个神奇的值来告诉容器自己决定吗?否则,是否有一种启发式方法可以

c++ - 如何使用 unordered_set?

这个问题在这里已经有了答案:UsingC++11unordered_setinVisualC++andclang(1个回答)关闭9年前。我正在尝试像这样定义一个unordered_set:unordered_setm_Points;当我编译它时,我得到以下错误:TheC++Standarddoesn'tprovideahashforthistype.类点:classPoint{private:intx,y;public:Point(inta_x,inta_y):x(a_x),y(a_y){}~Point(){}intgetX()const{returnx;}intgetY()const

c++ - 如何使用 unordered_set?

这个问题在这里已经有了答案:UsingC++11unordered_setinVisualC++andclang(1个回答)关闭9年前。我正在尝试像这样定义一个unordered_set:unordered_setm_Points;当我编译它时,我得到以下错误:TheC++Standarddoesn'tprovideahashforthistype.类点:classPoint{private:intx,y;public:Point(inta_x,inta_y):x(a_x),y(a_y){}~Point(){}intgetX()const{returnx;}intgetY()const

【C++】unordered_map和unordered_set的使用

文章目录前言一、unordered_map的使用及性能测试二、unordered_set的使用1.习题练习总结前言unordered系列关联式容器:在C++98中,STL提供了底层为红黑树结构的一系列关联式容器,在查询时效率可达到O(logN),即最差情况下需要比较红黑树的高度次,当树中的节点非常多时,查询效率也不理想。最好的查询是,进行很少的比较次数就能够将元素找到,因此在C++11中,STL又提供了4个unordered系列的关联式容器,这四个容器与红黑树结构的关联式容器使用方式基本类似,只是其底层结构不同.1.unordered_map 下面我们对比一下unordered_map和map

unordered_map详解

unordered_map介绍unordered_map是关联容器,含有带唯一键的键(key;it->first)-值(value;it->second)pair。搜索、插入和元素移除拥有平均常数时间复杂度。元素在内部不以任何特定顺序排序,而是组织进桶中。元素放进哪个桶完全依赖于其键的哈希。这允许对单独元素的快速访问,因为一旦计算哈希,则它准确指代元素所放进的桶。Hashtable和bucket由于unordered_map内部采用的hashtable的数据结构存储,所以,每个特定的key会通过一些特定的哈希运算映射到一个特定的位置,我们知道,hashtable是可能存在冲突的(多个key通过

c++ - 从 const unordered_map 读取对象

为什么不允许我从常量unordered_map中读取对象?constunordered_mapz;intval=z[5];//compileerrorclang下的错误如下:error:noviableoverloadedoperator[]fortype'constunordered_map'intval=z[5];考虑到使用constvector的等效代码可以正常工作,我有点困惑为什么会出现这种行为。 最佳答案 表达式z[5]调用映射的非常量成员函数。这是因为map的operator[]会在没有找到键的情况下插入一个新元素,所以

c++ - std::unordered_map::emplace 对象创建

我正在选择将事物放入unordered_map的两种方法之一:std::unordered_mapmap;map.emplace(std::piecewise_construct,std::forward_as_tuple(a),std::forward_as_tuple(b,c,d));对比std::unordered_mapmap;auto&value=map[a];if(value.isDefaultInitialized())value=DifferentValue(b,c,d);我做了一些实验,看看哪个表现更好,发现插入唯一元素时,行为(如效率)基本相同。但是,在插入重复项的

c++ - 在结构内部的 TR1 unordered_map 中定义哈希函数

根据this,可以像这样在TR1unordered_map中定义相等函数:#includeusingnamespacestd;usingnamespacestd::tr1;structfoo{...booloperator==(constfoo&b)const{return..;}};unordered_mapmap;是否可以用同样的方式定义哈希函数? 最佳答案 如果您想更改默认散列(或者更常见的是,为当前不受支持的类型提供散列),您可以提供std::tr1::hash的特化对于您的key类型:namespacestd{namesp

c++ - std::unordered_map::begin(int n) 行为

这是我正在运行的代码,使用g++4.6和-std=c++0xstd::unordered_mapum;um.insert(std::make_pair(42,43));um.insert(std::make_pair(342,343));um.insert(std::make_pair(142,143));um.insert(std::make_pair(242,243));for(autoe:um)std::cout这打印:24234242142现在我可以使用um.begin()->first或um.begin(0)->first访问242。可以使用um.begin(1)->firs