草庐IT

Union-Find

全部标签

c++ - 为什么 unordered_map "find + insert"比 "insert + check for success"快?

我使用unordered_map作为稀疏3D数组(128x128x128)将值插入到网格中,前提是网格单元仍然空闲。到目前为止,我总是使用find()检查单元格是否空闲,如果是,那么我使用insert()或emplace()添加了一个元素。现在我发现我可以使用insert和emplace的返回值来检查元素是否已添加,或者map中是否已经存在具有相同键的元素。我认为这可以提高性能,因为我可以完全删除find的使用。事实证明,不是通过插入而不查找来提高性能,而是性能实际上下降了,我不知道为什么。我已将我的应用程序简化为这个示例,其中点是随机生成的,然后插入到网格中。#include#inc

C++ union 与 reinterpret_cast

它出现在otherStackOverflowquestions并阅读ISO/IECdraftC++standard的§9.5.1使用union做文字的标准reinterpret_cast的数据是未定义的行为。考虑下面的代码。目标是取0xffff的整数值并将其解释为IEEE754浮点中的一系列位。(Binaryconvertshowsvisuallyhowthisisdone.)#includeusingnamespacestd;unionunionType{intmyInt;floatmyFloat;};intmain(){inti=0xffff;unionTypeu;u.myInt=

C++ union 与 reinterpret_cast

它出现在otherStackOverflowquestions并阅读ISO/IECdraftC++standard的§9.5.1使用union做文字的标准reinterpret_cast的数据是未定义的行为。考虑下面的代码。目标是取0xffff的整数值并将其解释为IEEE754浮点中的一系列位。(Binaryconvertshowsvisuallyhowthisisdone.)#includeusingnamespacestd;unionunionType{intmyInt;floatmyFloat;};intmain(){inti=0xffff;unionTypeu;u.myInt=

c++ - 错误 C2228 : left of '.size' must have class/struct/union

我在调用vector的size()时遇到此编译器错误。为什么?#include#include#include#include#include#includeusingnamespacestd;classVertex{floatfirstValue;floatsecondValue;floatthirdValue;Vertex(floatfirst,floatsecond,floatthird){firstValue=first;secondValue=second;thirdValue=third;}};intmain(){cout>actualLine;istringstreama

c++ - 错误 C2228 : left of '.size' must have class/struct/union

我在调用vector的size()时遇到此编译器错误。为什么?#include#include#include#include#include#includeusingnamespacestd;classVertex{floatfirstValue;floatsecondValue;floatthirdValue;Vertex(floatfirst,floatsecond,floatthird){firstValue=first;secondValue=second;thirdValue=third;}};intmain(){cout>actualLine;istringstreama

c++ - 如何在不破坏代码的情况下正确修复 "zero-sized array in struct/union"警告(C4200)?

我正在将一些代码集成到我的库中。这是一个针对速度进行了优化的复杂数据结构,所以我尽量不要对其进行过多修改。集成过程进展顺利,实际上几乎完成(它编译)。一件事仍然困扰着我。我多次收到C4200警告:warningC4200:nonstandardextensionused:zero-sizedarrayinstruct/unionCannotgeneratecopy-ctororcopy-assignmentoperatorwhenUDTcontainsazero-sizedarray代码有效,但这个警告让我毛骨悚然(尤其是带有copy-ctor的部分)。由于这样声明的结构而出现警告:#

c++ - 如何在不破坏代码的情况下正确修复 "zero-sized array in struct/union"警告(C4200)?

我正在将一些代码集成到我的库中。这是一个针对速度进行了优化的复杂数据结构,所以我尽量不要对其进行过多修改。集成过程进展顺利,实际上几乎完成(它编译)。一件事仍然困扰着我。我多次收到C4200警告:warningC4200:nonstandardextensionused:zero-sizedarrayinstruct/unionCannotgeneratecopy-ctororcopy-assignmentoperatorwhenUDTcontainsazero-sizedarray代码有效,但这个警告让我毛骨悚然(尤其是带有copy-ctor的部分)。由于这样声明的结构而出现警告:#

c++ - std::map 中 find() 的时间复杂度?

std::map类的find()函数效率如何?它是遍历所有元素以寻找O(n)的键,还是在平衡树中,或者它使用哈希函数还是什么? 最佳答案 Log(n)它基于一棵红黑树。编辑:n当然是map中的成员数。 关于c++-std::map中find()的时间复杂度?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/9961742/

c++ - std::map 中 find() 的时间复杂度?

std::map类的find()函数效率如何?它是遍历所有元素以寻找O(n)的键,还是在平衡树中,或者它使用哈希函数还是什么? 最佳答案 Log(n)它基于一棵红黑树。编辑:n当然是map中的成员数。 关于c++-std::map中find()的时间复杂度?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/9961742/

c++ - union 成员有一个重要的复制构造函数

这个问题在这里已经有了答案:Whycompilerdoesn'tallowstd::stringinsideunion?(7个回答)关闭6年前。我有一个如下所示的union:union{intintValue;doubledoubleValue;std::stringstringValue;void*pointerValue;}values;当我编译它时,我得到了这个错误信息(是的,我做了#include):./Value.hh:19:19:error:unionmember'stringValue'hasanon-trivialcopyconstructorstd::stringst