My code processes a huge number of values and I'm looking for an efficient structure to keep track of the top (N) values, where N is less than 10, so collecting ALL numbers then sorting the list and taking the first (N) is probably not the most efficient way.
To do that, I'm building a collection of fixed size N, to keep the top (N) values sorted in descending order. The Add(T value)
method of the sorted collection would add the value to the collection if value is higher than any of the existing values (in which case the last element is removed) or if the collection is not full.
I was able to implement what I wanted using a doubly LinkedList<T>
since it has fast insertion and removal, but I was wondering if using SortedDictionary<TKey, TValue>
or a priority queue would be better ?
Thank you.