.NET 中有排序的集合类型吗? [英] Is there a sorted collection type in .NET?

查看:23
本文介绍了.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 中有排序的集合类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆