Elin Modding Docs Doc
Loading...
Searching...
No Matches
PriorityQueueB.cs
1using System;
2using System.Collections.Generic;
3
4namespace Algorithms
5{
6 // Token: 0x0200075E RID: 1886
7 [Author("Franco, Gustavo")]
8 public class PriorityQueueB<T> : IPriorityQueue<T>
9 {
10 // Token: 0x06003675 RID: 13941 RVA: 0x00128C28 File Offset: 0x00126E28
11 public PriorityQueueB()
12 {
13 this.mComparer = Comparer<T>.Default;
14 }
15
16 // Token: 0x06003676 RID: 13942 RVA: 0x00128C46 File Offset: 0x00126E46
17 public PriorityQueueB(IComparer<T> comparer)
18 {
19 this.mComparer = comparer;
20 }
21
22 // Token: 0x06003677 RID: 13943 RVA: 0x00128C60 File Offset: 0x00126E60
23 public PriorityQueueB(IComparer<T> comparer, int capacity)
24 {
25 this.mComparer = comparer;
26 this.InnerList.Capacity = capacity;
27 }
28
29 // Token: 0x06003678 RID: 13944 RVA: 0x00128C88 File Offset: 0x00126E88
30 protected void SwitchElements(int i, int j)
31 {
32 T value = this.InnerList[i];
33 this.InnerList[i] = this.InnerList[j];
34 this.InnerList[j] = value;
35 }
36
37 // Token: 0x06003679 RID: 13945 RVA: 0x00128CC7 File Offset: 0x00126EC7
38 protected virtual int OnCompare(int i, int j)
39 {
40 return this.mComparer.Compare(this.InnerList[i], this.InnerList[j]);
41 }
42
43 // Token: 0x0600367A RID: 13946 RVA: 0x00128CEC File Offset: 0x00126EEC
44 public int Push(T item)
45 {
46 int num = this.InnerList.Count;
47 this.InnerList.Add(item);
48 while (num != 0)
49 {
50 int num2 = (num - 1) / 2;
51 if (this.OnCompare(num, num2) >= 0)
52 {
53 break;
54 }
55 this.SwitchElements(num, num2);
56 num = num2;
57 }
58 return num;
59 }
60
61 // Token: 0x0600367B RID: 13947 RVA: 0x00128D34 File Offset: 0x00126F34
62 public T Pop()
63 {
64 T result = this.InnerList[0];
65 int num = 0;
66 this.InnerList[0] = this.InnerList[this.InnerList.Count - 1];
67 this.InnerList.RemoveAt(this.InnerList.Count - 1);
68 for (;;)
69 {
70 int num2 = num;
71 int num3 = 2 * num + 1;
72 int num4 = 2 * num + 2;
73 if (this.InnerList.Count > num3 && this.OnCompare(num, num3) > 0)
74 {
75 num = num3;
76 }
77 if (this.InnerList.Count > num4 && this.OnCompare(num, num4) > 0)
78 {
79 num = num4;
80 }
81 if (num == num2)
82 {
83 break;
84 }
85 this.SwitchElements(num, num2);
86 }
87 return result;
88 }
89
90 // Token: 0x0600367C RID: 13948 RVA: 0x00128DE4 File Offset: 0x00126FE4
91 public void Update(int i)
92 {
93 int num;
94 int num2;
95 for (num = i; num != 0; num = num2)
96 {
97 num2 = (num - 1) / 2;
98 if (this.OnCompare(num, num2) >= 0)
99 {
100 break;
101 }
102 this.SwitchElements(num, num2);
103 }
104 if (num < i)
105 {
106 return;
107 }
108 for (;;)
109 {
110 int num3 = num;
111 int num4 = 2 * num + 1;
112 num2 = 2 * num + 2;
113 if (this.InnerList.Count > num4 && this.OnCompare(num, num4) > 0)
114 {
115 num = num4;
116 }
117 if (this.InnerList.Count > num2 && this.OnCompare(num, num2) > 0)
118 {
119 num = num2;
120 }
121 if (num == num3)
122 {
123 break;
124 }
125 this.SwitchElements(num, num3);
126 }
127 }
128
129 // Token: 0x0600367D RID: 13949 RVA: 0x00128E6C File Offset: 0x0012706C
130 public T Peek()
131 {
132 if (this.InnerList.Count > 0)
133 {
134 return this.InnerList[0];
135 }
136 return default(T);
137 }
138
139 // Token: 0x0600367E RID: 13950 RVA: 0x00128E9D File Offset: 0x0012709D
140 public void Clear()
141 {
142 this.InnerList.Clear();
143 }
144
145 // Token: 0x170010B1 RID: 4273
146 // (get) Token: 0x0600367F RID: 13951 RVA: 0x00128EAA File Offset: 0x001270AA
147 public int Count
148 {
149 get
150 {
151 return this.InnerList.Count;
152 }
153 }
154
155 // Token: 0x06003680 RID: 13952 RVA: 0x00128EB8 File Offset: 0x001270B8
156 public void RemoveLocation(T item)
157 {
158 int num = -1;
159 for (int i = 0; i < this.InnerList.Count; i++)
160 {
161 if (this.mComparer.Compare(this.InnerList[i], item) == 0)
162 {
163 num = i;
164 }
165 }
166 if (num != -1)
167 {
168 this.InnerList.RemoveAt(num);
169 }
170 }
171
172 // Token: 0x170010B2 RID: 4274
173 public T this[int index]
174 {
175 get
176 {
177 return this.InnerList[index];
178 }
179 set
180 {
181 this.InnerList[index] = value;
182 this.Update(index);
183 }
184 }
185
186 // Token: 0x04001D18 RID: 7448
187 protected List<T> InnerList = new List<T>();
188
189 // Token: 0x04001D19 RID: 7449
190 protected IComparer<T> mComparer;
191 }
192}