Make RPriorityQueue.Count point directly to the queue.Count instead of manually updating every operation.
This commit is contained in:
parent
3077b4d8b8
commit
dc98fb51b1
@ -3,7 +3,7 @@ namespace Pathfinding;
|
||||
public class RPriorityQueue<TKey, TPriority> where TKey : notnull
|
||||
{
|
||||
public Dictionary<TKey, TPriority> queue;
|
||||
public int Count { get; private set; }
|
||||
public int Count => queue.Count;
|
||||
|
||||
public RPriorityQueue()
|
||||
{
|
||||
@ -14,14 +14,12 @@ public class RPriorityQueue<TKey, TPriority> where TKey : notnull
|
||||
{
|
||||
if (!queue.TryAdd(key, priority))
|
||||
queue[key] = priority;
|
||||
Count = queue.Count;
|
||||
}
|
||||
|
||||
public TKey? Dequeue()
|
||||
{
|
||||
TKey? retKey = queue.MinBy(item => item.Value).Key;
|
||||
queue.Remove(retKey);
|
||||
Count = queue.Count;
|
||||
return retKey;
|
||||
}
|
||||
|
||||
@ -30,7 +28,6 @@ public class RPriorityQueue<TKey, TPriority> where TKey : notnull
|
||||
int before = Count;
|
||||
queue = queue.Where(queueitem => !elements.Contains(queueitem.Key))
|
||||
.ToDictionary(item => item.Key, item => item.Value);
|
||||
Count = queue.Count;
|
||||
return before - Count;
|
||||
}
|
||||
|
||||
@ -38,7 +35,6 @@ public class RPriorityQueue<TKey, TPriority> where TKey : notnull
|
||||
{
|
||||
int before = Count;
|
||||
queue = queue.IntersectBy(exceptKeys, item => item.Key).ToDictionary(item => item.Key, item => item.Value);
|
||||
Count = queue.Count;
|
||||
return before - Count;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user