forked from E-riCA0/StawdewValley
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityQueue.cs
More file actions
83 lines (74 loc) · 1.97 KB
/
PriorityQueue.cs
File metadata and controls
83 lines (74 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Decompiled with JetBrains decompiler
// Type: StardewValley.PriorityQueue
// Assembly: Stardew Valley, Version=1.2.6400.27469, Culture=neutral, PublicKeyToken=null
// MVID: 77B7094A-F6F0-4ACC-91F4-E335E2733EDB
// Assembly location: D:\SteamLibrary\steamapps\common\Stardew Valley\Stardew Valley.exe
using System.Collections.Generic;
namespace StardewValley
{
public class PriorityQueue
{
private int total_size;
private SortedDictionary<int, Queue<PathNode>> nodes;
public PriorityQueue()
{
this.nodes = new SortedDictionary<int, Queue<PathNode>>();
this.total_size = 0;
}
public bool IsEmpty()
{
return this.total_size == 0;
}
public bool Contains(PathNode p, int priority)
{
if (!this.nodes.ContainsKey(priority))
return false;
return this.nodes[priority].Contains(p);
}
public PathNode Dequeue()
{
if (!this.IsEmpty())
{
foreach (Queue<PathNode> pathNodeQueue in this.nodes.Values)
{
if (pathNodeQueue.Count > 0)
{
this.total_size = this.total_size - 1;
return pathNodeQueue.Dequeue();
}
}
}
return (PathNode) null;
}
public object Peek()
{
if (!this.IsEmpty())
{
foreach (Queue<PathNode> pathNodeQueue in this.nodes.Values)
{
if (pathNodeQueue.Count > 0)
return (object) pathNodeQueue.Peek();
}
}
return (object) null;
}
public object Dequeue(int priority)
{
this.total_size = this.total_size - 1;
return (object) this.nodes[priority].Dequeue();
}
public void Enqueue(PathNode item, int priority)
{
if (!this.nodes.ContainsKey(priority))
{
this.nodes.Add(priority, new Queue<PathNode>());
this.Enqueue(item, priority);
}
else
{
this.nodes[priority].Enqueue(item);
this.total_size = this.total_size + 1;
}
}
}
}