private void growHeap()
 {
     capacity = (capacity * 2) + 1;
     HeapEntry[] newHeap = new HeapEntry[capacity];
     System.Array.Copy(heap, 0, newHeap, 0, count);
     heap = newHeap;
 }
        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 < he.Priority))
            {
                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 < heap[child + 1].Priority))
                {
                    child++;
                }
                heap[index] = heap[child];
                index       = child;
                child       = getLeftChild(index);
            }
            bubbleUp(index, he);
        }