private void GrowHeap() { _capacity = (_capacity * 2) + 1; var newHeap = new HeapEntry <T> [_capacity]; Array.Copy(_heap, 0, newHeap, 0, _count); _heap = newHeap; }
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue(CAPACITY_NAME, _capacity); info.AddValue(COUNT_NAME, _count); var heapCopy = new HeapEntry <T> [_count]; Array.Copy(_heap, 0, heapCopy, 0, _count); info.AddValue(HEAP_NAME, heapCopy, typeof(HeapEntry <T>[])); }
private void BubbleUp(int index, HeapEntry <T> he) { int parent = GetParent(index); // note: (index > 0) means there is a parent while ((index > 0) && (_heap[parent].Priority.CompareTo(he.Priority) < 0)) { _heap[index] = _heap[parent]; index = parent; parent = GetParent(index); } _heap[index] = he; }
private void TrickleDown(int index, HeapEntry <T> he) { int child = GetLeftChild(index); while (child < _count) { if (((child + 1) < _count) && (_heap[child].Priority.CompareTo(_heap[child + 1].Priority) < 0)) { child++; } _heap[index] = _heap[child]; index = child; child = GetLeftChild(index); } BubbleUp(index, he); }