mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-05 07:49:22 +00:00
Move many mods to Deprecated folder, fix spelling
This commit is contained in:
parent
5e822cec8d
commit
0042590aa6
539 changed files with 7475 additions and 3120 deletions
|
@ -0,0 +1,43 @@
|
|||
namespace NAK.BetterContentLoading;
|
||||
|
||||
public class ConcurrentPriorityQueue<TElement, TPriority> where TPriority : IComparable<TPriority>
|
||||
{
|
||||
private readonly object _lock = new();
|
||||
private readonly SortedDictionary<TPriority, Queue<TElement>> _queues = new();
|
||||
|
||||
public void Enqueue(TElement item, TPriority priority)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_queues.TryGetValue(priority, out var queue))
|
||||
{
|
||||
queue = new Queue<TElement>();
|
||||
_queues[priority] = queue;
|
||||
}
|
||||
queue.Enqueue(item);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryDequeue(out TElement item, out TPriority priority)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_queues.Count == 0)
|
||||
{
|
||||
item = default;
|
||||
priority = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var firstQueue = _queues.First();
|
||||
priority = firstQueue.Key;
|
||||
var queue = firstQueue.Value;
|
||||
item = queue.Dequeue();
|
||||
|
||||
if (queue.Count == 0)
|
||||
_queues.Remove(priority);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue