适用于 .NET 的高效、不可变、可扩展集合
在我看来,.NET 极度缺乏安全、不可变的集合类型,特别是 BCL,但我也没有看到太多外部工作。有没有人知道(最好是)生产质量、快速、不可变的 .NET 集合库。快速列表类型至关重要。我还没有准备好切换到 F#。
*编辑:搜索者请注意,这很快就会被纳入 BCL:.NET 不可变集合
It seems to me there is an extreme lack of safe, immutable collection types for .NET, in particular BCL but I've not seen much work done outside either. Do anyone have any pointers to a (preferably) production quality, fast, immutable collections library for .NET. A fast list type is essential. I'm not yet prepared to switch to F#.
*Edit: Note to searchers, this is being rolled into the BCL soon: .NET immutable collections
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可能想查看
Microsoft.FSharp.CollectionsFSharp.Core
程序集中的 code> 命名空间。您不必使用 F# 进行编程即可使用这些类型。请记住,从 F# 外部使用时,名称会有所不同。例如,F# 中的
Map
在 C# 中称为FSharpMap
。You might want to take a look at the
Microsoft.FSharp.Collections
namespace in theFSharp.Core
assembly. You do not have to program in F# to make use of these types.Keep in mind that the names will be different when used from outside F#. For example, the
Map
in F# is known asFSharpMap
from C#..NET BCL 团队发布了 .NET 4.5 的不可变集合预览
The .NET BCL team has released a Immutable Collections preview for .NET 4.5
我前段时间写了一个
ImmutableList
类:所有修改集合的方法都会返回修改后的副本。为了履行
IList
接口约定,显式实现了标准 Add/Remove/Delete/Clear 方法,但它们会抛出InvalidOperationException
。这个类使用了一些非标准扩展方法,它们是:
这是一个用于创建
ImmutableList
实例的辅助类:这是一个使用示例:
我不能说它是生产质量的,因为我还没有彻底测试过,但到目前为止它似乎工作得很好......
I wrote an
ImmutableList<T>
class some time ago :All methods that modify the collection return a modified copy. In order to fulfill with the
IList<T>
interface contract, the standard Add/Remove/Delete/Clear methods are implemented explicitly, but they throw anInvalidOperationException
.This class uses a few non-standard extension methods, here they are :
And here's a helper class to create instances of
ImmutableList<T>
:Here's a usage example :
I can't say it's production quality, as I haven't tested it thoroughly, but so far it seems to work just fine...
C5 浮现在脑海中,但我不确定它有多快。它已经存在很多年了,而且非常稳定。
此外,在我看来,
List.AsReadOnly()
的工作做得相当好,但不幸的是,没有字典或任意ICollection
的等效项。C5 springs to mind, but I'm not sure how fast it is. It has been around for years, and is very stable.
Additionally,
List<T>.AsReadOnly()
does the job rather well IMO, but unfortunately there is no equivalent for dictionaries or arbitraryICollection<T>
's.您可以查看 其他 或 System.collections .concurrent
You may look at Extras or System.collections.concurrent tutorial
您可以尝试 BclExtras作者:贾里德·帕。
You could try BclExtras by JaredPar.