How to efficiently search vectors in C++
本问题已经有最佳答案,请猛点这里访问。
我需要找出
我的searchvec也有一百万个矢量
例如,如果我的searchvec是(9,28,4,2)我的集装箱vec是((1,3678,27),(9,28,4,2),(595,85,52))。然后searchvec(9,28,4,2)出现在((1,3678,27),(9,28,4,2),(595,85,52))。但是,如果我的searchvec是(23、84、25、11),那么它不在containervec中。
编辑:我尝试了std::find,但是perf工具显示它花费的时间最多。有没有其他我可以使用的数据结构?
这不是副本。正如我在问题中提到的那样,std::find的性能很差。同样,你标记为"无处"的副本也谈到了性能问题。
(P)向量比较词汇表中所列的可比性。So a EDOCX1 cía 0 get its compar functions for free(unless you want to specify a different behavior).In the following demo you can see why EDOCX1 universal 1 can work with containers of EDOCX1(p)字母名称
(P)使用STL Find Function。(p)(P)Keep in mind that there is also a find□uu if function,which you can use if your search is more complex,I.E.If you're not just looking for an element,but,for example,want see if there is an element that fulfils a certain condition,for example,a string that starts with"ABC".(Find'uu if would give you an iterator that points to the first such element).(p)(P)See this link:http://www.sgi.com/tech/stl/find.html(p)
(P)Crossrorrelate searchvec with containerve,(p)(P)在.wikipedia.org/wiki/cross-correction(p)(P)This can be done like shown here:(p)(P)Pattern recognition with double vectors(p)(P)Which will give you the similary of the compared part of containervat to searchvec.(p)