diff options
Diffstat (limited to 'ARMeilleure/Translation/PriorityQueue.cs')
-rw-r--r-- | ARMeilleure/Translation/PriorityQueue.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ARMeilleure/Translation/PriorityQueue.cs b/ARMeilleure/Translation/PriorityQueue.cs new file mode 100644 index 00000000..ab593dc0 --- /dev/null +++ b/ARMeilleure/Translation/PriorityQueue.cs @@ -0,0 +1,39 @@ +using System.Collections.Concurrent; + +namespace ARMeilleure.Translation +{ + class PriorityQueue<T> + { + private ConcurrentQueue<T>[] _queues; + + public PriorityQueue(int priorities) + { + _queues = new ConcurrentQueue<T>[priorities]; + + for (int index = 0; index < priorities; index++) + { + _queues[index] = new ConcurrentQueue<T>(); + } + } + + public void Enqueue(int priority, T value) + { + _queues[priority].Enqueue(value); + } + + public bool TryDequeue(out T value) + { + for (int index = 0; index < _queues.Length; index++) + { + if (_queues[index].TryDequeue(out value)) + { + return true; + } + } + + value = default(T); + + return false; + } + } +}
\ No newline at end of file |