Is there a sorted collection type in .NET?(.NET 中有排序的集合类型吗?)
问题描述
我正在寻找一个能够将所有物品保持井井有条的容器.我查看了 SortedList,但这需要一个单独的键,并且不允许重复键.我也可以只使用一个未排序的容器,并在每次插入后对其进行显式排序.
I'm looking for a container that keeps all its items in order. I looked at SortedList, but that requires a separate key, and does not allow duplicate keys. I could also just use an unsorted container and explicitly sort it after each insert.
用法:
- 偶尔插入
- 按顺序频繁遍历
- 最好不要使用与实际对象分开的键,使用比较函数进行排序.
- 需要对等价对象进行稳定排序,但这不是必需的.
- 不需要随机访问.
我意识到我可以自己构建一个平衡的树结构,我只是想知道框架是否已经包含这样的野兽.
I realize I can just build myself a balanced tree structure, I was just wondering if the framework already contains such a beast.
推荐答案
你可能想看看 Wintellect电源集合.它在 CodePlex 上可用,并且包含很多非常有用的集合.项目中的 OrderedBag 集合正是您要寻找的.它本质上使用 红黑树 来提供非常有效的排序.
You might want to take a look at the Wintellect Power Collections. It is available on CodePlex and contains quite a few collections that are very helpful. The OrderedBag collection in the project is exactly what you are looking for. It essentially uses a red-black tree to provide a pretty efficient sort.
这篇关于.NET 中有排序的集合类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET 中有排序的集合类型吗?
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
