From bd703ca5eab9ba6fd8c440e06ee92863b990c8a5 Mon Sep 17 00:00:00 2001 From: astrofishgames Date: Tue, 21 Feb 2017 15:57:01 +0000 Subject: [PATCH] fix removing elements other than top --- .../Reactive/Internal/PriorityQueue.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Rx.NET/Source/System.Reactive.Core/Reactive/Internal/PriorityQueue.cs b/Rx.NET/Source/System.Reactive.Core/Reactive/Internal/PriorityQueue.cs index 010634868f..94a62ded18 100644 --- a/Rx.NET/Source/System.Reactive.Core/Reactive/Internal/PriorityQueue.cs +++ b/Rx.NET/Source/System.Reactive.Core/Reactive/Internal/PriorityQueue.cs @@ -33,26 +33,23 @@ private bool IsHigherPriority(int left, int right) return _items[left].CompareTo(_items[right]) < 0; } - private void Percolate(int index) + private int Percolate(int index) { if (index >= _size || index < 0) - return; + return index; var parent = (index - 1) / 2; if (parent < 0 || parent == index) - return; + return index; if (IsHigherPriority(index, parent)) { var temp = _items[index]; _items[index] = _items[parent]; _items[parent] = temp; - Percolate(parent); + return Percolate(parent); } - } - private void Heapify() - { - Heapify(0); + return index; } private void Heapify(int index) @@ -91,7 +88,8 @@ private void RemoveAt(int index) { _items[index] = _items[--_size]; _items[_size] = default(IndexedItem); - Heapify(); + if (Percolate(index) == index) + Heapify(index); if (_size < _items.Length / 4) { var temp = _items;