internal void Enqueue(PriorityQueueElement <TPriority, TValue> value) { value.InsertionIndex = _insertionIndex++; value.Index = _heap.Count; _heap.Add(value); BubbleUp(value.Index); }
private bool BubbleUpPriorityFilter(PriorityQueueElement <TPriority, TValue> value, int index) { if (index <= 0) { return(false); } var parent = GetParentIndex(index); var comparison = _comparer.Compare(_heap[parent].Priority, value.Priority); if (comparison == -1 * (int)_priority) { return(true); } // Resolve ties based on queue order if (_stability == Stability.Unmanaged) { return(false); } return(comparison == 0 && _heap[parent].InsertionIndex.CompareTo(value.InsertionIndex) == -1 * (int)_stability); }