GroupBy 中的内存节省
对许多项目(GB)运行 LINQ to Objects GroupBy()
方法可能会消耗内存。如果 IEnumerable
已经按键排序,我们可以编写一个不消耗太多内存的 GroupBy
。
我在哪里可以找到具有这种方法的库?
Running LINQ to Objects GroupBy()
method for many items (gigabytes) can be memory consuming. If the IEnumerable<T>
is already ordered by the key, we could write an GroupBy
that didn't consume as much memory.
Where can I find a library that has such method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
框架中没有任何东西可以做到这一点。如果您不需要实际的
IGrouping<,>
您可以使用此:如果您需要完整的
IGrouping<,>
实现,则会稍微困难一些 -但您随时可以获取我的Edulinq 实现。GroupByChanges
的实现几乎不会改变 - 只需更改currentList
赋值以将密钥传递给Grouping
构造函数:There's nothing in the framework to do this. If you don't need an actual
IGrouping<,>
you could use this:If you need a full
IGrouping<,>
implementation it'll be slightly harder - but you could always grab my Edulinq implementation.The implementation of
GroupByChanges
would change very little - just change thecurrentList
assignments to pass in the key to theGrouping
constructor:你的问题很具体。您不太可能找到已经做到这一点的库。如果您的项目是按您用于分组的键排序的,那么您自己对该列表进行“分组”是一项近乎微不足道的任务。
Your problem is very specific. It is highly unlikely that you will find a library that already does this. If your items are ordered by the key which you use to group, it is a near-trivial task to 'group' this list yourself.
您可以轻松地自己实现它:
You could easily implement it yourself:
和托马斯一样,但速度稍快一些
Like Thomas' but slightly faster