.NET SortedDictionary But Sorted By Values

Posted by Michael Covelli on Stack Overflow See other posts from Stack Overflow or by Michael Covelli
Published on 2010-04-11T23:03:32Z Indexed on 2010/04/11 23:13 UTC
Read the original article Hit count: 408

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 values in my inverse dictionary would have to be unique. And there are some cases where they may not be.

Any ideas of something in the .NET libraries already that would work for me?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#