aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/MinHeap.cs
diff options
context:
space:
mode:
authorUbitUmarov2019-01-25 20:46:03 +0000
committerUbitUmarov2019-01-25 20:46:03 +0000
commite3d0ec6f405a74a831a98090f33b4a7d756d36c3 (patch)
treef20a66abca653243e21da33bf3117b76a829bd98 /OpenSim/Framework/MinHeap.cs
parentOoops fix bad locking (diff)
downloadopensim-SC-e3d0ec6f405a74a831a98090f33b4a7d756d36c3.zip
opensim-SC-e3d0ec6f405a74a831a98090f33b4a7d756d36c3.tar.gz
opensim-SC-e3d0ec6f405a74a831a98090f33b4a7d756d36c3.tar.bz2
opensim-SC-e3d0ec6f405a74a831a98090f33b4a7d756d36c3.tar.xz
a few changes on priority queues and their heap
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/MinHeap.cs36
1 files changed, 20 insertions, 16 deletions
diff --git a/OpenSim/Framework/MinHeap.cs b/OpenSim/Framework/MinHeap.cs
index 2149b8a..2731e99 100644
--- a/OpenSim/Framework/MinHeap.cs
+++ b/OpenSim/Framework/MinHeap.cs
@@ -65,7 +65,7 @@ namespace OpenSim.Framework
65 { 65 {
66 if (handle != null) 66 if (handle != null)
67 { 67 {
68 handle.Clear(); 68 handle.heap = null;
69 handle = null; 69 handle = null;
70 } 70 }
71 value = default(T); 71 value = default(T);
@@ -96,8 +96,8 @@ namespace OpenSim.Framework
96 public MinHeap(Comparison<T> comparison) : this(DEFAULT_CAPACITY, comparison) { } 96 public MinHeap(Comparison<T> comparison) : this(DEFAULT_CAPACITY, comparison) { }
97 public MinHeap(int _capacity, Comparison<T> _comparison) 97 public MinHeap(int _capacity, Comparison<T> _comparison)
98 { 98 {
99 minCapacity = _capacity; 99 minCapacity = 16;
100 items = new HeapItem[minCapacity]; 100 items = new HeapItem[_capacity];
101 comparison = _comparison; 101 comparison = _comparison;
102 size = version = 0; 102 size = version = 0;
103 } 103 }
@@ -169,8 +169,8 @@ namespace OpenSim.Framework
169 int current, parent; 169 int current, parent;
170 170
171 for (current = index, parent = (current - 1) / 2; 171 for (current = index, parent = (current - 1) / 2;
172 (current > 0) && (comparison(items[parent].value, item.value)) > 0; 172 (current > 0) && (comparison(items[parent].value, item.value)) > 0;
173 current = parent, parent = (current - 1) / 2) 173 current = parent, parent = (current - 1) / 2)
174 { 174 {
175 Set(items[parent], current); 175 Set(items[parent], current);
176 } 176 }
@@ -187,11 +187,12 @@ namespace OpenSim.Framework
187 private void BubbleDown(int index) 187 private void BubbleDown(int index)
188 { 188 {
189 HeapItem item = items[index]; 189 HeapItem item = items[index];
190 int current, child; 190 int current;
191 int child;
191 192
192 for (current = index, child = (2 * current) + 1; 193 for(current = index , child = (2 * current) + 1;
193 current < size / 2; 194 current < size / 2;
194 current = child, child = (2 * current) + 1) 195 current = child, child = (2 * current) + 1)
195 { 196 {
196 if ((child < size - 1) && comparison(items[child].value, items[child + 1].value) > 0) 197 if ((child < size - 1) && comparison(items[child].value, items[child + 1].value) > 0)
197 ++child; 198 ++child;
@@ -293,14 +294,17 @@ namespace OpenSim.Framework
293 throw new ArgumentOutOfRangeException("index"); 294 throw new ArgumentOutOfRangeException("index");
294 295
295 items[index].Clear(); 296 items[index].Clear();
296 if (--size > 0 && index != size) 297 --size;
297 { 298 if (size > 0)
298 Set(items[size], index); 299 { if(index != size)
299 items[size].ClearRef(); 300 {
300 if (!BubbleUp(index)) 301 Set(items[size], index);
301 BubbleDown(index); 302 items[size].ClearRef();
303 if (!BubbleUp(index))
304 BubbleDown(index);
305 }
302 } 306 }
303 if(size == 0 && items.Length > 4 * minCapacity) 307 else if(items.Length > 4 * minCapacity)
304 items = new HeapItem[minCapacity]; 308 items = new HeapItem[minCapacity];
305 } 309 }
306 310