sorteddictionary

.NET SortedDictionary But Sorted By Values

喜欢而已 提交于 2020-01-20 08:10:12
问题 I need a data structure that acts like a SortedDictionary<int, double> but is sorted based on the values rather than the keys. I need it to take about 1-2 microseconds to add and remove items when we have about 3000 items in the dictionary. My first thought was simply to switch the keys and values in my code. This very nearly works. I can add and remove elements in about 1.2 microseconds in my testing by doing this. But the keys have to be unique in a SortedDictionary so that means that

.NET SortedDictionary But Sorted By Values

别说谁变了你拦得住时间么 提交于 2020-01-20 08:09:52
问题 I need a data structure that acts like a SortedDictionary<int, double> but is sorted based on the values rather than the keys. I need it to take about 1-2 microseconds to add and remove items when we have about 3000 items in the dictionary. My first thought was simply to switch the keys and values in my code. This very nearly works. I can add and remove elements in about 1.2 microseconds in my testing by doing this. But the keys have to be unique in a SortedDictionary so that means that

.NET SortedDictionary But Sorted By Values

妖精的绣舞 提交于 2020-01-20 08:08:07
问题 I need a data structure that acts like a SortedDictionary<int, double> but is sorted based on the values rather than the keys. I need it to take about 1-2 microseconds to add and remove items when we have about 3000 items in the dictionary. My first thought was simply to switch the keys and values in my code. This very nearly works. I can add and remove elements in about 1.2 microseconds in my testing by doing this. But the keys have to be unique in a SortedDictionary so that means that

when should I use a sorteddictionary instead of a dictionary [duplicate]

浪尽此生 提交于 2019-12-22 01:34:19
问题 This question already has answers here : SortedList<>, SortedDictionary<> and Dictionary<> (6 answers) Closed 5 years ago . As I wrote in some of my last posts I am still quite new to the c# world so it comes that I wrote small benchmark to compare Dictionary, Hashtable, SortedList and SortedDictionary against each other. The test runs with 8000 iterations and from 50 to 100000 elements. I tested adding of new elements, search for elements and looping through some elements all random. The

SortedList vs. SortedDictionary vs. Sort()

偶尔善良 提交于 2019-12-20 10:31:16
问题 This is a continuation of questions like this one. Are there any guidelines for tweaking the performance? I don't mean gains in big-O, just saving some linear time. For example, how much does pre-sorting save on either SortedList or SortedDictionary ? Say I have a person-class with 3 properties to sort on, one of them is age in years. Should I bucket the objects on age first? Should I first sort on one property, then use the resulting list/dictionary to sort on two properties and so on? Any