草庐IT

Unordered

全部标签

c++ - unordered_map/unordered_set 中元组的通用哈希

为什么不std::unordered_map,string>只是开箱即用?必须为tuple定义散列函数很繁琐。,例如templatestructdo_hash>{size_toperator()(std::tupleconst&tt)const{...}};Buildinganunorderedmapwithtuplesaskeys(MatthieuM.)展示了如何为boost::tuple自动执行此操作.有没有在不使用可变参数模板的情况下对c++0x元组执行此操作?这当然应该在标准中:( 最佳答案 这适用于gcc4.5,允许所有包

c++ - unordered_map/unordered_set 中元组的通用哈希

为什么不std::unordered_map,string>只是开箱即用?必须为tuple定义散列函数很繁琐。,例如templatestructdo_hash>{size_toperator()(std::tupleconst&tt)const{...}};Buildinganunorderedmapwithtuplesaskeys(MatthieuM.)展示了如何为boost::tuple自动执行此操作.有没有在不使用可变参数模板的情况下对c++0x元组执行此操作?这当然应该在标准中:( 最佳答案 这适用于gcc4.5,允许所有包

c++ - std::unordered_map::find 使用不同于 Key 类型的类型?

我有一个unordered_map使用字符串类型作为键:std::unordered_mapmap;一个std::hash为string提供特化,以及ASA适合operator==.现在我还有一个“字符串View”类,它是一个指向现有字符串的弱指针,避免了堆分配:classstring_view{string*data;size_tbegin,len;//...};现在我希望能够使用string_view来检查map中是否存在键。目的。不幸的是,std::unordered_map::find需要Key参数,不是通用的T论据。(当然,我可以将一个“提升”为string,但这会导致我想避

c++ - std::unordered_map::find 使用不同于 Key 类型的类型?

我有一个unordered_map使用字符串类型作为键:std::unordered_mapmap;一个std::hash为string提供特化,以及ASA适合operator==.现在我还有一个“字符串View”类,它是一个指向现有字符串的弱指针,避免了堆分配:classstring_view{string*data;size_tbegin,len;//...};现在我希望能够使用string_view来检查map中是否存在键。目的。不幸的是,std::unordered_map::find需要Key参数,不是通用的T论据。(当然,我可以将一个“提升”为string,但这会导致我想避

unordered_map 中字符串的 C++ 哈希函数

似乎C++在标准库中没有字符串的散列函数。这是真的吗?什么是在unordered_map中使用字符串作为键的工作示例,可以与任何c++编译器一起使用? 最佳答案 C++STL提供模板specializationsstd::hash用于各种字符串类。您可以将std::string指定为std::unordered_map:的键类型#include#includeintmain(){std::unordered_mapmap;map["string"]=10;return0;} 关于unor

unordered_map 中字符串的 C++ 哈希函数

似乎C++在标准库中没有字符串的散列函数。这是真的吗?什么是在unordered_map中使用字符串作为键的工作示例,可以与任何c++编译器一起使用? 最佳答案 C++STL提供模板specializationsstd::hash用于各种字符串类。您可以将std::string指定为std::unordered_map:的键类型#include#includeintmain(){std::unordered_mapmap;map["string"]=10;return0;} 关于unor

c++ - 在不使用 if 的情况下插入/更新 std::unordered_map 元素的最快方法是什么?

我目前有很多如下代码:std::unordered_mapmy_dict;...//Ifthekeydoesexistinthedictionaryif(my_dict.count(key)==1){my_dict[key]=value;}//Ifitsanewkeyelse{my_dict.insert(std::make_pair(key,value));}有什么方法可以通过每次覆盖值来加快速度? 最佳答案 您只需这样做(对于map和unordered_map)mydict[key]=value;

c++ - 在不使用 if 的情况下插入/更新 std::unordered_map 元素的最快方法是什么?

我目前有很多如下代码:std::unordered_mapmy_dict;...//Ifthekeydoesexistinthedictionaryif(my_dict.count(key)==1){my_dict[key]=value;}//Ifitsanewkeyelse{my_dict.insert(std::make_pair(key,value));}有什么方法可以通过每次覆盖值来加快速度? 最佳答案 您只需这样做(对于map和unordered_map)mydict[key]=value;

c++ - C++ STL unordered_map 如何解决冲突?

C++STLunordered_map如何解决冲突?查看http://www.cplusplus.com/reference/unordered_map/unordered_map/,它说“唯一键容器中的两个元素不能有等价的键。”这应该意味着容器确实在解决冲突。但是,该页面并没有告诉我它是如何做到的。我知道一些解决冲突的方法,比如使用链表和/或探测。我想知道的是c++STLunordered_map是如何解决的。 最佳答案 标准对此的定义比大多数人似乎意识到的要多一些。具体而言,标准要求(§23.2.5/9):Theelements

c++ - C++ STL unordered_map 如何解决冲突?

C++STLunordered_map如何解决冲突?查看http://www.cplusplus.com/reference/unordered_map/unordered_map/,它说“唯一键容器中的两个元素不能有等价的键。”这应该意味着容器确实在解决冲突。但是,该页面并没有告诉我它是如何做到的。我知道一些解决冲突的方法,比如使用链表和/或探测。我想知道的是c++STLunordered_map是如何解决的。 最佳答案 标准对此的定义比大多数人似乎意识到的要多一些。具体而言,标准要求(§23.2.5/9):Theelements