将 3D 数组的体积展平为 1D 对象数组
给定我有一个类型的 3D 地图,其长度和宽度是均匀的,但深度是锯齿状的:
public class Map<T>
{
T[,][] map;
...
}
返回由 2D 区域定义的体积内存在的所有类型对象的 1D 数组的最佳方法是什么?该区域内的深度。例如,我可能有一个数组符号覆盖,如下所示:
public IEnumerable<T> this[Rectangle area]
{
get {...}
}
或者只是
public IEnumerable<T> this[int x, int y, int width, int length]
{
get {...}
}
我真诚地希望有一个快速的 LINQ 解决方案,但性能优于解决方案的视觉优雅。返回的展平数组中对象的顺序并不重要。如果有人对此有任何建议或经验,请分享您的智慧。
或者,如果我可以使用另一个数据结构来执行我不知道的相同功能,我会很乐意使用它。
如果我的问题不清楚,请询问更多详细信息。
Give I have a 3D map of type whose the length and width are uniform but the depth is jagged:
public class Map<T>
{
T[,][] map;
...
}
What is the best way to return a 1D array of all of the objects of type that exist within a volume defined by a 2D area and all of depth within that area. For example I might have an array notation override as follows:
public IEnumerable<T> this[Rectangle area]
{
get {...}
}
or just
public IEnumerable<T> this[int x, int y, int width, int length]
{
get {...}
}
I am honestly hoping for an fast LINQ solution but performance is preferable to visual elegance of the solution. The order of the objects within the flattened array that is returned is unimportant. If anyone has any suggestions or experience with this please share your wisdom.
Alternatively if there is another data structure at my disposal that can perform the same function that I am unaware of, I will gladly use that instead.
If something about my question is unclear please ask for further details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在寻找这样的东西吗?
Are you looking for something like this?
这可能也有效(没有 Linq)
This might work as well (without Linq)