Tag: sorteddictionary

什么是Ruby(1.8.7)类似于C#/ .NET中的SortedDictionary?

我需要在ruby(1.8.7)中按排序哈希值保存值。 哪些数据最适合?

如何在排序字典中找到两个键之间的点

我有一个排序字典,包含测量数据点作为键/值对。 为了确定非测量数据点的值,我想使用相应值的线性插值来推断两个已知键之间的值。 一旦我有两个键/值对,我就明白了如何计算非测量数据点。 我不知道的是如何找出它之间的关键。 有没有比“for”循环(我正在考虑函数/ LINQ查询)更优雅的方法来确定我的数据点位于哪两个键之间?

线程安全的SortedDictionary

我创建了一个使用SortedDictionary来存储和操作数据的类。 除非在multithreading环境中实现,否则该类很有效。 现在,我想通过为内部SortedDictionary类编写包装类来使类线程安全。 我想使用Reader-Writer Locks来实现它,但是现在,我在编写包装器本身时遇到了问题。 具体来说,我不确定如何为字典实现Enumerator 。 这是我现在的完整代码。 public class ConcurrentSortedDictionary : IEnumerable<KeyValuePair> { #region Variables SortedDictionary _dict; #endregion #region Constructors public ConcurrentSortedDictionary() { _dict = new SortedDictionary(); } public ConcurrentSortedDictionary(IComparer comparer) { _dict = new SortedDictionary(comparer); } public ConcurrentSortedDictionary(IDictionary dictionary) { _dict = new SortedDictionary(dictionary); } public ConcurrentSortedDictionary(IDictionary dictionary, IComparer comparer) { _dict = […]

在SortedDictionary中查找最接近的值

我有一个SortedDictionary SortedDictionary myDict; 现在我想找到X之上的第一个值。我可以做这样的事情 foreach (var iKey in MyDict.Keys) { if (iKey >= thresholdKey) { foundKey = iKey; break; } } 但这并不是明智的表现。 还有更好的建议吗? (在集合中是否有一种方法可以像二进制搜索SortedDictionary那样?)

如何从SortedDictionary获取以前的密钥?

我有包含键值对的字典。 SortedDictionary dictionary=new SortedDictionary(); dictionary.Add(1,33); dictionary.Add(2,20); dictionary.Add(4,35); 我想从已知的键值获取先前的键值对。 在上面的例子中,如果我有键4,那我怎么能得到 ?

SortedDictionary是红黑树吗?

我在互联网上看到了几个关于此的引用,但没有官方文档? 谁能告诉我在哪里可以获得有关此信息?

.NET SortedDictionary但按值排序

我需要一个像SortedDictionary一样的数据结构,但是它是根据值而不是键来排序的。 当我们在字典中有大约3000个项目时,我需要大约1-2微秒来添加和删除项目。 我的第一个想法是简单地在我的代码中切换键和值。 这几乎是有效的。 通过这样做,我可以在测试中添加和删除大约1.2微秒的元素。 但是密钥必须在SortedDictionary中是唯一的,这意味着我的逆字典中的值必须是唯一的。 在某些情况下,他们可能不会。 .NET库中的某些想法已经对我有用吗?