什么.NET词典支持"找到最近的密钥QUOT;操作? [英] What .NET dictionary supports a "find nearest key" operation?
问题描述
我把一些C ++ code到C#和它调用的std ::地图:: LOWER_BOUND(K)找到其关键是等于或大于k的映射条目。不过,我没有看到任何方式做同样的事情。NET的SortedDictionary。我怀疑我可以实现使用排序列表一个解决办法,但遗憾的是SortedList的速度太慢(O(n)的插入和删除键)。我该怎么办?
I'm converting some C++ code to C# and it calls std::map::lower_bound(k) to find an entry in the map whose key is equal to or greater than k. However, I don't see any way to do the same thing with .NET's SortedDictionary. I suspect I could implement a workaround using SortedList, but unfortunately SortedList is too slow (O(n) for inserting and deleting keys). What can I do?
注:我发现了一个变通方法使用该把我的特殊情况下的优势......具体来说,我的钥匙是一个人口密集,起售价只有超过0的整数,所以我用了一个名单,其中,TValue>因为我的字典的列表索引作为重点,并寻求于k一键等于或大于可以在只有少数几个循环迭代来完成。但它仍然是很高兴看到回答了原来的问题。
Note: I found a workaround using that takes advantage of my particular scenario... Specifically, my keys are a dense population of integers starting at just over 0, so I used a List<TValue> as my dictionary with the list index serving as the key, and searching for a key equal or greater than k can be done in only a few loop iterations. But it would still be nice to see the original question answered.
推荐答案
我创建相关的B +树提供此功能的任何数据类型的三种数据结构: BList&LT; T&GT;
, BDictionary&LT; K,V&GT ;
和 BMultiMap&LT; K,V&GT;
。所有这些数据结构提供了 FindLowerBound()
和 FindUpperBound()
的工作就像方法C ++的的LOWER_BOUND
和 UPPER_BOUND
。
I created three data structures related to B+ trees that provide this functionality for any data type: BList<T>
, BDictionary<K,V>
and BMultiMap<K,V>
. Each of these data structures provide FindLowerBound()
and FindUpperBound()
methods that work like C++'s lower_bound
and upper_bound
.
这篇关于什么.NET词典支持&QUOT;找到最近的密钥QUOT;操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!