private void growHeap() { capacity = (capacity * 2) + 1; HeapEntry[] newHeap = new HeapEntry[capacity]; System.Array.Copy(heap, 0, newHeap, 0, count); heap = newHeap; }
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue(capacityName, capacity); info.AddValue(countName, count); HeapEntry[] heapCopy = new HeapEntry[count]; Array.Copy(heap, 0, heapCopy, 0, count); info.AddValue(heapName, heapCopy, typeof(HeapEntry[])); }
private void bubbleUp(int index, HeapEntry 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 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); }