I have a need for a fairly specialised collection .NET, and I don't think that the BCL can help me, but I thought I'd throw it out there for if anyone knew of something similar.
Basically, my requirements are thus:
- I have a list of pairs of values, such as: (3, 10), (5, 10), (3, 7), (5, 5)
- Order is important, ie. (3, 10) != (10, 3)
- Duplicates of individual values are fine, but duplicate pairs should be dropped (preferably silently).
- The kicker is, I need this list sorted all the time. I'm only ever interested in the first value in the list as defined by the sort algorithm at any one time.
So, some example code of what I want to be able to do (as I envision it would probably be implemented, other implementations that fit the above are fine to):
public class Pair
{
public Paid(int first, int second)
{ First = first; Second = second; }
public int First { get; set; }
public int Second { get; set; }
}
SortedQueue<Pair> foo = new SortedQueue<Pair>((left, right) => {
return right.First - left.First;
});
foo.Add(new Pair(10, 3));
foo.Add(new Pair(4, 6));
foo.Add(new Pair(6, 15));
foo.Add(new Pair(6, 13)); // This shouldn't cause a problem
Pair current = foo.Shift(); // current = (4, 6)