简体   繁体   English

索引复杂对象的最快集合类型

[英]Fastest Type of Collection of indexed complex Ocjects

I'm looking for the most elegant, fastest and most efficient way to store several objects of the class Point with an index/key in any kind of collection.我正在寻找最优雅、最快和最有效的方法来存储 class Point的多个对象,并在任何类型的集合中使用索引/键。

Point contains attributes like index , posX , posY , area , neighborPoints[] , AdjacentTriangles[] , etc. and are used for creating a Delaunay-Triangulation and a Voronoi-Mesh. Point包含indexposXposYareaneighborPoints[]AdjacentTriangles[]等属性,用于创建 Delaunay-Triangulation 和 Voronoi-Mesh。
For reasons of selection the single points should have an index in the collection, but don't need to be ordered.出于选择的原因,单点应该在集合中有一个索引,但不需要排序。
While triangulating, I'm creating and deleting points.在进行三角测量时,我正在创建删除点。 Also I want to loop through all points in the collection.我还想遍历集合中的所有点。 Hence, the type of collection should be optimized for these operations.因此,应针对这些操作优化集合类型。

In the beginning I used a List<Point> for storing the points and the occurence in the list was identical with the index of the point.一开始我使用List<Point>来存储点,并且列表中的出现与点的索引相同。 In case of deleting one point of the list, I had to decrease all indices of the higher points.如果删除列表中的一个点,我必须减少较高点的所有索引。 This sounds pretty inconvenient and time-consuming to me.这对我来说听起来很不方便且耗时。

This is why I tried Dictionary<int, Point> afterwards.这就是我后来尝试Dictionary<int, Point>的原因。 Here the indices are fixed and if I delete for example the second point, then all higher points, maybe Point[5] stays Point[5] , just Point[1] is not there anymore (return is null ).这里的索引是固定的,如果我删除例如第二个点,那么所有更高的点,也许Point[5]保持Point[5] ,只是Point[1]不再存在(返回是null )。 However, my runtimes are now even longer (see picture), although I don't have to do the index-shifting anymore.然而,我的运行时间现在更长了(见图),尽管我不再需要进行索引移动了。 (Why is this?) (为什么是这样?) 运行时

Using a Hashmap makes no sence to me, since then I would not be able to use calls like Point.posX (error code CS1061), because in a Hashmap the datatype is not set.使用Hashmap对我来说毫无意义,从那时起我将无法使用Point.posX (错误代码 CS1061)之类的调用,因为在 Hashmap 中未设置数据类型。

Do you have any suggestion for a efficient type of collection with faster performance?您对性能更快的高效集合有什么建议吗?

You could sort the points along a hilbert curve.您可以沿希尔伯特曲线对点进行排序。 Basically the Bowyer-Watson algorithm use the hilbert curve. Bowyer-Watson 算法基本上使用希尔伯特曲线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM