如果嵌套int[]
包含坐标 x,y,我如何使用 SequenceEqual 比较它们?
List 是一组坐标。我想检查所有其他列表,看看它们是否具有相同数量的坐标以及相同的坐标值。如果它们都匹配,我想删除多余的。否则,离开它。
private List<List<int[]>> combineList(List<List<int[]>> matches){
Debug.Log (matches.Count());
foreach(List<int[]> tileGroup in matches){
foreach(List<int[]> other in matches){
if(other == tileGroup) continue;
if(sequenceEqual(tileGroup, other)){
matches.Remove(other);
}
}
}
Debug.Log (matches.Count());
return matches;
}
private bool sequenceEqual(List<int[]> groupA, List<int[]> groupB){
if(groupA.Count() == groupB.Count()){
int i = 0, j = 0;
Dictionary<int, int[]> dictA = new Dictionary<int, int[]>(),
dictB = new Dictionary<int, int[]>();
foreach(int[] coordinate in groupA){
dictA.Add (i, coordinate);
i++;
}
foreach(int[] coordinate in groupB){
dictB.Add (j, coordinate);
j++;
}
return dictA.Values.SequenceEqual(dictB.Values);
}
return false;
}