草庐IT

unordered_container

全部标签

c++ - 在 C++ std::unordered_map 中预分配桶

我正在使用来自gnu++0x的std::unordered_map来存储大量数据。我想为大量元素预先分配空间,因为我可以限制使用的总空间。我想做的是打电话:std::unordered_mapm;m.resize(pow(2,x));其中x是已知的。std::unordered_map不支持这个。如果可能,我宁愿使用std::unordered_map,因为它最终会成为标准的一部分。其他一些限制:需要可靠的O(1)访问和map变异。所需的散列和比较函数已经是非标准的并且有些昂贵。O(logn)突变(与std::map一样)太昂贵了。->昂贵的哈希和比较也使得基于摊销的增长方式过于昂贵。

java - 像 Java 集的 'contains any' 这样的东西?

我有两个相同类型的集合,A和B。我必须找出A是否包含集合B中的任何元素。在不迭代集合的情况下,最好的方法是什么?Set库有contains(object)和containsAll(collection),但没有containsAny(collection)。 最佳答案 不会Collections.disjoint(A,B)工作?来自文档:Returnstrueifthetwospecifiedcollectionshavenoelementsincommon.因此,如果集合包含任何公共(public)元素,则该方法返回false。

python - Python 是否有字符串 'contains' 子字符串方法?

这个问题的答案是communityeffort。编辑现有答案以改进这篇文章。它目前不接受新的答案或交互。我正在寻找Python中的string.contains或string.indexof方法。我想做:ifnotsomestring.contains("blah"):continue 最佳答案 使用inoperator:if"blah"notinsomestring:continue 关于python-Python是否有字符串'contains'子字符串方法?,我们在StackOver

ruby-on-rails - rails : How to send emails to a recipient containing umlauts?

我想发送一封具有以下设置的电子邮件defregistration_confirmation(user)recipientsuser.username+""from"NetzwerkMuensterland"subject"VielenDankfürIhreRegistrierung"body:user=>usercontent_type"text/html"end主题行包含变音符号并且工作正常。日志告诉我,它是这样编码的:=?utf-8?Q?Vielen_Dank_f=C3=BCr_Ihre_Registrierung?=但是,如果user.username包含变音符号,则电子邮件将不

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,但这会导致我想避

ruby - `exec' : string contains null byte (ArgumentError)

cmd="snvco#{rep}--username#{svn_user}--password#{pxs}"putscmd#thiscodewotksandprintsallvarsvaluesnormallyexec(cmd)xpto.rb:69:in`exec':stringcontainsnullbyte(ArgumentError)fromxpto.rb:69$ruby-vruby1.8.7(2010-01-10patchlevel249)[i686-linux]$gem-v1.3.7这是怎么回事?我该如何解决这个问题? 最佳答案

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