private void growHeap() { m_Capacity = (m_Capacity * 2) + 1; HeapEntry <Titem>[] newHeap = new HeapEntry <Titem> [m_Capacity]; System.Array.Copy(m_Heap, 0, newHeap, 0, (int)m_Count); m_Heap = newHeap; }
private void bubbleUp(long index, HeapEntry <Titem> he) { long parent = getParent(index); // note: (index > 0) means there is a parent while ((index > 0) && (m_Heap[parent].Priority < he.Priority)) { m_Heap[index] = m_Heap[parent]; index = parent; parent = getParent(index); } m_Heap[index] = he; }
private void trickleDown(long index, HeapEntry <Titem> he) { long child = getLeftChild(index); while (child < m_Count) { if (((child + 1) < m_Count) && (m_Heap[child].Priority < m_Heap[child + 1].Priority)) { child++; } m_Heap[index] = m_Heap[child]; index = child; child = getLeftChild(index); } bubbleUp(index, he); }