问题描述:C#滤波器双[]的值的列表
我具有表示向量,其中第0向量元素对应于所述矢量的物理长度和其他双[]值的列表3 (1到3)对应于x,y和z分量。该列表包含大约1000000个条目。所以perfermonce将是一个问题。我根据矢量的长度对列表进行了排序。现在我需要过滤列表,使得长度不同的矢量保持不变,如果长度相同,则位置1到3中包含不同的条目(不是permuatations)的那些滤波器保持如示例中所示。如果您需要更多信息,请告诉我。 在过滤过程中不应更改矢量。
问题:如何使用C#实现以及如果可能的话使用linq?
实施例:
0, 0, 0; 0,0000 -> select
0, 1, -1; 8,2883 -> select
1, 0, -1; 8,2883 -> not select
0, -1, 1; 8,2883 -> not select
-1, 0, 1; 8,2883 -> not select
1, -1, 0; 8,2883 -> not select
-1, 1, 0; 8,2883 -> not select
1, 1, -2; 14,3558 -> select
...
2, 2, -5; 38,6145 -> select
-2, -2, 5; 38,6145 -> not select
1, 4, -4; 38,6145 -> select
4, 1, -4; 38,6145 -> not select
-1, -4, 4; 38,6145 -> not select
-4, -1, 4; 38,6145 -> not select
-1, 4, -4; 38,6145 -> not select
4, -1, -4; 38,6145 -> not select
-4, 1, 4; 38,6145 -> not select
1, -4, 4; 38,6145 -> not select
-2, 5, -2; 38,6145 -> not select
5, -2, -2; 38,6145 -> not select
2, -5, 2; 38,6145 -> not select
-5, 2, 2; 38,6145 -> not select
4, -4, -1; 38,6145 -> not select
-4, 4, -1; 38,6145 -> not select
-4, 4, 1; 38,6145 -> not select
4, -4, 1; 38,6145 -> not select
...
CODE:
所有的private static double absm = 0;
private static int[] m = new int[3];
private static int[] m2 = new int[3];
private static List<double[]> ihkl1 = new List<double[]>();
private static List<double[]> ihkl2 = new List<double[]>();
...
private static void init_latt()
{
for (int i = -kmax[2]; i < kmax[2]; i++)
{
m[2] = i;
for (int j = -kmax[1]; j < kmax[1]; j++)
{
m[1] = j;
for (int k = -kmax[0]; k < kmax[0]; k++)
{
m[0] = k;
absm = calcabsm(metten, m);
if (absm < gmax)
{
double[] row1 = new double[4];
row1[0] = absm;
row1[1] = (double)m[0];
row1[2] = (double)m[1];
row1[3] = (double)m[2];
ihkl1.Add(row1);
}
}
}
}
ihkl2 = ihkl1.AsParallel().OrderBy(x => x[0]).ToList();
}
...
第一个建议:从“列表”更改为“列表”,其中“Vector”是四个值的适当封装。你的代码将会更加清晰。 –
2013-03-12 10:00:46
[你到目前为止尝试过什么](http://whathaveyoutried.com)?你卡在哪里?请张贴您当前的代码并解释它的缺点。 – Oded 2013-03-12 10:00:50
list.distinct(); – 1Mayur 2013-03-12 10:01:24