[英]Collecting unique sorted vectors
I have hundred millions of sorted vectors containing floating numbers, the size of each array are the same and reasonably small(less than ten), I need to collect the unique vectors out of such vectors, 我有数亿个包含浮点数的排序向量,每个数组的大小相同且相当小(小于10),我需要从此类向量中收集唯一的向量,
vec1 = {1.0, 1.2, 1.4, 1.6, 1.8}
vec2 = {1.0, 1.1, 1.3, 1.5, 1.7}
vec2 = {1.0, 1.3, 1.4, 1.5, 1.6}
...
SomeTree ={vec1, vec2, vec3 ...}
an array is considered the "same" as another only if every elements are numerically the same(up to some precision), Is there any special tree or other data structure suitable for such purpose ? 仅当每个元素在数值上都相同(达到一定精度)时,数组才被视为与另一个数组“相同”。是否有任何特殊的树或其他数据结构适合于此目的?
Yes, there is. 就在这里。 It is called
std::set
: 它称为
std::set
:
#include <vector>
#include <set>
int main()
{
std::set<std::vector<double>> s{
{ 1.0, 1.1, 1.3, 1.5, 1.7 },
{ 1.0, 1.2, 1.4, 1.6, 1.8 },
{ 1.0, 1.1, 1.3, 1.5, 1.7 },
{ 1.0, 1.3, 1.4, 1.5, 1.6 },
{ 1.0, 1.2, 1.4, 1.6, 1.8 },
{ 1.0, 1.1, 1.3, 1.5, 1.7 },
{ 1.0, 1.2, 1.4, 1.6, 1.8 },
{ 1.0, 1.3, 1.4, 1.5, 1.6 },
{ 1.0, 1.3, 1.4, 1.5, 1.6 },
};
}
It's likely that you will want to deeply analyze the Compare
parameter of the template, in order to have a definition of less
that fits your requirements. 您可能需要深入分析模板的
Compare
参数,以便定义一个less
符合您要求的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.