草庐IT

unordered-multiset

全部标签

c++ - 为什么 std::unordered_map 有保留方法?

根据this你不能为std::map:保留空间No,themembersofthemapareinternallystoredinatreestructure.Thereisnowaytobuildthetreeuntilyouknowthekeysandvaluesthataretobestored.从这里很明显为什么std::map会缺少reserve()方法,它在cppreference.com上就是这样做的。但是,std::unordered_mapdoes有一个reserve()方法,但是当我尝试将它与operator[]、insert()或emplace()尽管我先调用了r

c++ - 为什么 std::unordered_map 有保留方法?

根据this你不能为std::map:保留空间No,themembersofthemapareinternallystoredinatreestructure.Thereisnowaytobuildthetreeuntilyouknowthekeysandvaluesthataretobestored.从这里很明显为什么std::map会缺少reserve()方法,它在cppreference.com上就是这样做的。但是,std::unordered_mapdoes有一个reserve()方法,但是当我尝试将它与operator[]、insert()或emplace()尽管我先调用了r

c++ - 如何使用具有 pair<int,int> vector 元素的 unordered_set

我想拥有类似的东西unordered_set>>us;但即使没有配对:#include#includeusingnamespacestd;intmain(){unordered_set>um;}失败了:Infileincludedfrom/usr/include/c++/4.8/bits/hashtable.h:35:0,from/usr/include/c++/4.8/unordered_set:47,fromprog.cpp:2:/usr/include/c++/4.8/bits/hashtable_policy.h:Ininstantiationof‘structstd::__d

c++ - 如何使用具有 pair<int,int> vector 元素的 unordered_set

我想拥有类似的东西unordered_set>>us;但即使没有配对:#include#includeusingnamespacestd;intmain(){unordered_set>um;}失败了:Infileincludedfrom/usr/include/c++/4.8/bits/hashtable.h:35:0,from/usr/include/c++/4.8/unordered_set:47,fromprog.cpp:2:/usr/include/c++/4.8/bits/hashtable_policy.h:Ininstantiationof‘structstd::__d

c++ - 在 unordered_map 中使用元组

我想在我的unordered_map中使用由int、char、char组成的元组。我是这样做的:#include#include#include#include#includeusingnamespacestd;tuplekk;unordered_mapmap;intmain(){map[1,"c","b"]=23;return0;}但这给了我以下错误:map.cpp:9:21:error:type/valuemismatchatargument1intemplateparameterlistfor‘templateclassstd::unordered_map’map.cpp:9:2

c++ - 在 unordered_map 中使用元组

我想在我的unordered_map中使用由int、char、char组成的元组。我是这样做的:#include#include#include#include#includeusingnamespacestd;tuplekk;unordered_mapmap;intmain(){map[1,"c","b"]=23;return0;}但这给了我以下错误:map.cpp:9:21:error:type/valuemismatchatargument1intemplateparameterlistfor‘templateclassstd::unordered_map’map.cpp:9:2

c++ - std::unordered_set<T>::insert(T&&): 如果存在则移动参数

这个问题是关于C++11标准库中几个函数的规范,这些函数将它们的参数作为右值引用,但并不在所有情况下都使用它们。一个例子是std::unordered_set::insert(T&&).很明显,这个方法将使用T的移动构造函数构造容器中的元素,如果它不存在的话。但是,如果元素已经存在于容器中会怎样?我很确定没有理由更改案例中的对象。但是,我没有在C++11标准中找到任何支持我的主张的内容。这里有一个例子来说明为什么这可能很有趣。以下代码从std::cin读取行并删除第一次出现的重复行。std::unordered_setseen;std::stringline;while(getline

c++ - std::unordered_set<T>::insert(T&&): 如果存在则移动参数

这个问题是关于C++11标准库中几个函数的规范,这些函数将它们的参数作为右值引用,但并不在所有情况下都使用它们。一个例子是std::unordered_set::insert(T&&).很明显,这个方法将使用T的移动构造函数构造容器中的元素,如果它不存在的话。但是,如果元素已经存在于容器中会怎样?我很确定没有理由更改案例中的对象。但是,我没有在C++11标准中找到任何支持我的主张的内容。这里有一个例子来说明为什么这可能很有趣。以下代码从std::cin读取行并删除第一次出现的重复行。std::unordered_setseen;std::stringline;while(getline

c++ - std::hash_set vs std::unordered_set,它们是一回事吗?

我知道hash_set是非标准的,而unordered_set是标准的。但是,我想知道,性能方面,两者之间有什么区别?为什么要分开存在? 最佳答案 C++标准规定的unordered_容器的复杂性要求基本上没有为实现留下太多空间,它必须是某种哈希表。该标准是在充分意识到大多数供应商已经将这些数据结构作为扩展部署的情况下编写的。编译器供应商通常将这些容器称为“HashMap”或“哈希集”,这可能是您所指的(标准中没有文字std::hash_set,但是我认为GCC在单独的命名空间中有一个,对于其他编译器也是如此)。编写新标准时,作者希

c++ - std::hash_set vs std::unordered_set,它们是一回事吗?

我知道hash_set是非标准的,而unordered_set是标准的。但是,我想知道,性能方面,两者之间有什么区别?为什么要分开存在? 最佳答案 C++标准规定的unordered_容器的复杂性要求基本上没有为实现留下太多空间,它必须是某种哈希表。该标准是在充分意识到大多数供应商已经将这些数据结构作为扩展部署的情况下编写的。编译器供应商通常将这些容器称为“HashMap”或“哈希集”,这可能是您所指的(标准中没有文字std::hash_set,但是我认为GCC在单独的命名空间中有一个,对于其他编译器也是如此)。编写新标准时,作者希