实现您自己的LINQ和放大器; IEnumerable的< T>自己的、放大器、LINQ、GT

2023-09-04 02:17:43 作者:萧萧易水

在一个项目,我的工作,真的有巨大的集合(1M-1B元素),事情被修改为集合居多。

In a project I am working on, there are really huge collections (1M-1B elements), and things are modified as collections mostly.

这是一个实时的应用程序,这样的表现是最重要的。

It's a real-time app, and so the performance is paramount.

有关的一些操作,如反向,二分查找(可能吗?)的,等会遭受比其他人更喜欢选择等。

For some of the operations, like Reverse, BinarySearch (possible?), etc will suffer more than others like Select, etc.

是否可行实现自己的IEnumerable有可能的MoveNext,移动$ P $光伏发电等与自身实现LINQ的扩展,充分利用这些优势?

Is it feasible to implement one's own IEnumerable with possible MoveNext, MovePrev, etc and own implemented LINQ extensions that take advantages of these?

如果这是要发生的事,它的会发生在项目结束。因为我们需要得到它的工作,再使其更快。

If this is gonna happen, it's gonna happen at the end of the project. Because we need to get it working first, then make it faster.

这所有的一切不应该太多的工作,对吧?

All in all this shouldn't be too much work, right?

推荐答案

这是非常肯定可以创建自己的实现可枚举这可能会特殊情况的一些情况的。你基本上要检测你自己的集合类型(或者可能只集合,如名单,其中,T> ),并使用更有效的实现适用

It's very definitely possible to create your own implementation of Enumerable which might special-case some situations. You'd basically want to detect your own collection types (or possibly just collections such as List<T>) and use a more efficient implementation where applicable.

我有我用来演示实施LINQ到一个小时的对象,你可能喜欢示例项目看的例子。这不是一个完整的执行情况,特别是少的效率比真正的LINQ到对象 - 但你可能还觉得很有意思

I have a sample project which I used to demo "implementing LINQ to Objects in an hour" which you might like to look at for examples. It's not a full implementation and in particular it's less efficient than the real LINQ to Objects - but you may still find it interesting.

另外,你可能会发现 i4o(索引LINQ)确实需要开箱一切 - 或者说你会过得更好促进该不是从头开始。值得一试。

Alternatively, you may find that i4o (Indexed LINQ) does everything you need out of the box - or that you would be better off contributing to that than starting from scratch. Worth checking out.

只要记住,在一天结束的时候,LINQ基本上再加上语法糖一个不错的设计。 C#编译器不知道的什么的特别之处 System.Linq.Enumerable 例如。

Just remember that at the end of the day, LINQ is basically a nice design coupled with syntactic sugar. The C# compiler doesn't know anything special about System.Linq.Enumerable, for example.