I am writing a specific priority queue. Its structure needs to be something as follows:
Priority(<int>) Data(List<Object>)
1 a, b, g, h
3 c, d, j
4 k
10 e, f, i
I need to be able to efficiently find if a list exists for a given priority; if not, create the list and add the message, otherwise append the message to the existing list.
I have written a red-black tree, but this seems like overkill for this, and may not be the fastest solution. It also has the drawback of not being able to easily grab the messages by priority, which I need to be able to do once the writing has been completed.
I thought about Dictionary, but unless I am mistaken, it doesn't have a simple way to say "if the key __ exists, give me the value corresponding to it, otherwise give me null". Or am I missing something?
EDIT
My current implementation is to have 32 fixed lists. The applicable list is added to and the applicable bit set in a 32-bit flag. I use De Bruijn's algorithm to get the LSB. This is efficient, but is adding other complexity that I want to alleviate.
Maybe you should use Dictionary<int,List<object>>
public void Add(int priority,object data)
{
if(dictionary.ContainsKey(priority))
dictionary[priority].Add(data);
else
dictionary.Add(priority,new List<object>{data});
}