草庐IT

hash_algorithm

全部标签

c++ - (Re)Using std::algorithms with non-standard containers

我有一个“列”容器类型:structMyColumnType{//Data:Eachrowrepresentsamemberofanobject.vectora;//Allvectorsareguaranteedtohavealwaysvectorb;//thesamelength.vectorc;voidcopy(intfrom_pos,intto_pos);//Thecolumntypeprovidesaninterfacevoidswap(intpos_a,intpos_b);//forcopying,swapping,...voidpush_back();//Andforres

c++ - 如何创建具有 64 位输出的良好 hash_combine(受 boost::hash_combine 启发)

目前Boost有hash_combine函数输出32位无符号整数(准确的说是size_t)。一些引用:http://www.boost.org/doc/libs/1_43_0/doc/html/hash/reference.html#boost.hash_combinehttp://www.boost.org/doc/libs/1_43_0/doc/html/hash/combine.htmlMagicnumberinboost::hash_combine我想探索如何创建64位版本的hash_combine。第一件事是在64位中获得黄金比例或任何其他无理数。第二部分是使用轮类。这部分相

algorithm - 如何压缩指针?例如。任意位指针

我正在编写一个复杂的树数据结构,其中存储了很多指针。指针本身会占用大量空间,而这正是我希望节省的空间。所以我来问问有没有这方面的例子。例如:对于64位数据类型,如果它指向的数据肯定是连续的,我可以使用32位或更少的指针吗?我找到了一篇名为TransparentPointerCompressionforLinkedDataStructures的论文,但我认为可能有更简单的解决方案。更新:这是一个octree.关于GPU的一篇论文是GigaVoxels:AVoxel-BasedRenderingPipelineForEfficientExplorationOfLargeAndDetaile

c++ - std::hash 特化使用 sfinae?

作为练习,我试图看看我是否可以使用SFINAE为std::pair和std::创建一个std::hash特化:tuple当它的所有模板参数都是无符号类型时。我对它们有一点经验,但据我了解,散列函数需要已经使用typenameEnabled=void进行模板化,以便我添加特化。我不太确定从这里去哪里。这是一个不起作用的尝试。#include#include#include#includenamespacestd{templatestructhash,std::enable_if_t::value>>{size_toperator()(conststd::pair&x)const{retu

c++ - std::hash 模板偏特化

我用模板写了一些类:template>classmy_list;我应该为这个类编写::std::hash特化。我怎样才能做到这一点?简单的偏特化:namespacestd{templateclasshash>{public:size_toperator()(constmy_list&x)const{return...;}};}但是我不能写简单的偏特化,因为它被C++ISO禁止:ISO/IEC14882Thirdedition2011-09-0117.6.4.2.1Namespacestd[namespace.std]2ThebehaviorofaC++programisundefine

c++ - 为什么 std::hash 不专用于 std::reference_wrapper?

我以为会是这样,但我在我的标准库实现(gcc-4.8.2)中找不到它。为什么std::hash还没有专门用于std::reference_wrapper?#pragmaonce#includenamespacestd{templatestructhash>{size_toperator()(constreference_wrapper&r)const{returnstd::hash()(r.get());}};} 最佳答案 std::reference_wrapper主要用于在默认复制值的实用程序中提供引用语义,例如std::bin

c++ - std::type_info::hash_code() 的唯一性和 "should"的含义

是否意味着要保证相同的std::type_info::hash_code()值表示相同的类型?Cplusplus.com似乎是这么说的:Thisfunctionreturnsthesamevalueforanytwotype_infoobjectsthatcompareequal,anddifferentvaluesfordistincttypesthatdonot.[Emphasismine]Cppreference似乎另有说法:Returnsanunspecifiedvalue,whichisidenticalforobjects,referringtothesametype.No

c++ - 如何修复 "<hash_map> is deprecated and will be REMOVED. Please use <unordered_map>"?

我正在学习C++,所以我正在阅读Programming:PrinciplesandPracticeusingC++这本书。我正在进行第一个练习,即如何制作“Hello,World!”。使用MicrosoftVisualStudio2015编写的程序。我使用了书中提供的源代码。#include"../../std_lib_facilities.h"//headerfilerecommendedbybookintmain()//C++programsstartbyexecutingthefunctionmain{cout但是,当我尝试构建一个可执行程序时收到两个错误,如下所示:Intell

c++ - 为什么 std::hash<T> 不专用于 char*?

为什么C++标准不指定std::hash专门用于char*,constchar*,unsignedchar*,constunsignedchar*,ETC?即,它将散列C字符串的内容,直到找到终止null。将我自己的特化注入(inject)std的任何危害我自己的代码的命名空间? 最佳答案 Whydoesn'ttheC++standardspecifythatstd::hashisspecializedforchar*,constchar*,unsignedchar*,constunsignedchar*,etc?看起来它起源于pr

c++ - std::hash 是否保证在 stdlib 发行版中相同

如果我使用libstdc++做了std::hash然后在即将到来的C++11VS2012库上做了一个-他们会匹配吗?我假设哈希实现不是C++规范的一部分,并且会因分布而异? 最佳答案 标准只说明了这一点:20.8.12ClasstemplatehashTheunorderedassociativecontainersdefinedin23.5usespecializationsoftheclasstemplatehashasthedefaulthashfunction.ForallobjecttypesKeyforwhichther