From dc98fb51b1eda1ce2fabdb7b6f04e8f05bbcb9b3 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 17 May 2023 19:00:47 +0200 Subject: [PATCH] Make RPriorityQueue.Count point directly to the queue.Count instead of manually updating every operation. --- Pathfinding/RPriorityQueue.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Pathfinding/RPriorityQueue.cs b/Pathfinding/RPriorityQueue.cs index e710afa..1bbba5a 100644 --- a/Pathfinding/RPriorityQueue.cs +++ b/Pathfinding/RPriorityQueue.cs @@ -3,7 +3,7 @@ namespace Pathfinding; public class RPriorityQueue where TKey : notnull { public Dictionary queue; - public int Count { get; private set; } + public int Count => queue.Count; public RPriorityQueue() { @@ -14,14 +14,12 @@ public class RPriorityQueue 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 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 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; }