【发布时间】:2020-08-22 14:28:22
【问题描述】:
我想从 sortedlist 或其他类似的排序数据结构中获取范围键。
例如;
SortedList<long, string> testSorted = new SortedList<long, string>();
testSorted.Add(1, "a");
testSorted.Add(4, "b");
testSorted.Add(15, "c");
testSorted.Add(12, "d");
testSorted.Add(10, "e");
testSorted.Add(8, "f");
int wantspecifickey = 7;
int index = testSorted.GetClosestIndex(wantspecifickey);
int range = 1;
List<long> rangeIndex = testSorted.GetRangeIndexKey(index , range);
最接近 7 的键值为 8。
所以索引值为2。
之后,在索引 2(key: 8)处,索引范围 1 内的索引的键是 4 8 和 10。
你们有什么好主意来解决我的问题吗?
PS。我不必使用排序列表。如果有更高效的数据结构,也请告诉我。
【问题讨论】:
-
尝试使用 SortedSet 它有 GetViewBetween 方法和其他有用的方法,可以帮助您解决这个问题
标签: c# indexing data-structures key sortedlist