C# .NET 排序不佳的容器
我要用 C# 编写一个基于事件的模拟器。我需要一个具有以下功能的调度程序排序容器:
- 键 - 值对按键排序存储(时间、委托对)
- 按键高效插入和删除(删除最小的项目,插入是任意的)
- 最小的项目(键值对)可以查询。
我需要的实际上是一个非常基本的二叉树或排序队列或类似的东西。但我在 .NET 中的选项 - SortedList 和 SortedDictionary - 并不令人满意。第一个存在插入和删除的效率问题,第二个存在查询最小项目的问题。
我应该开始实现自己的容器还是我会错过一些东西?令人难以置信的是,没有一个内置容器可以满足我的需求。
谢谢!
(更新:我正在寻找.NET 2.0下的解决方案)
I'm to write an event based simulator in C#. I need a sorted container for the scheduler that has the following capabilities:
- Key - Value pairs are stored sorted by the key (Time, Delegate pairs)
- Efficient inserts and removes by key (Smallest items are removed, inserts are arbitrary)
- The smallest item (key value pair) can be queried.
What I need is actually a very basic binary tree or a sorted queue or something similar. But the options I have in .NET - SortedList and SortedDictionary - are unsatisfactory. The first has efficiency issues with inserts and removes, the second has problems with querying the smallest items.
Should I start implementing my own container or I miss something? It is so unbelievable that there is no built in container that fits my needs.
Thanks!
(update: Im looking for a solution under .NET 2.0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您自己跟踪最小的项目,您仍然可以使用
SortedDictionary
。但我和 @Frédéric 有同样的问题 -
sortedDictionary.First()
有什么问题吗?编辑:根据 Frédéric 的建议,.NET 2.0 的
Enumerable.First
实现:You could still use a
SortedDictionary
if you kept track of the smallest item yourself.But I have the same question as @Frédéric - what's wrong with
sortedDictionary.First()
?Edit: As per Frédéric's suggestion, an
Enumerable.First
implementation for .NET 2.0:如果 .NET 集合没有提供您正在寻找的功能和性能,您可能需要考虑 C5 库。
If the .NET collections don't provide the functionality and performance that you're looking for, you might want to consider the C5 library.