public void CascadeDown(int index)
        {
            int      smallerChild;
            HeapNode top = heapArray[index];

            while (index < CurrentSize / 2)
            {
                int leftChild  = 2 * index + 1;
                int rightChild = leftChild + 1;
                if (rightChild < CurrentSize && heapArray[leftChild].Key > heapArray[rightChild].Key)
                {
                    smallerChild = rightChild;
                }
                else
                {
                    smallerChild = leftChild;
                }
                if (top.Key <= heapArray[smallerChild].Key)
                {
                    break;
                }
                heapArray[index] = heapArray[smallerChild];
                index            = smallerChild;
            }
            heapArray[index] = top;
        }
        public void CascadeUp(int index)
        {
            int      parent = (index - 1) / 2;
            HeapNode bottom = heapArray[index];

            while (index > 0 && heapArray[parent].Key > bottom.Key)
            {
                heapArray[index] = heapArray[parent];
                index            = parent;
                parent           = (parent - 1) / 2;
            }
            heapArray[index] = bottom;
        }
        // problematic without garbage collection
        public HeapNode RemoveRoot()
        {
            if (CurrentSize == 0)
            {
                return(null);
            }

            HeapNode root = heapArray[0];

            heapArray[0] = heapArray[--CurrentSize];
            CascadeDown(0);

            CoordinatesHashTable.Remove(root.Value.Coordinates);

            return(root);
        }
        public bool Insert(PathNode node)
        {
            if (CurrentSize == maxSize)
            {
                return(false);
            }
            if (CurrentSize > MaximumCount)
            {
                MaximumCount = CurrentSize;
            }

            // HeapNode newNode = new HeapNode(node);
            heapArray[CurrentSize] = new HeapNode(node);                                                      //newNode;

            CoordinatesHashTable.Add(heapArray[CurrentSize].Value.Coordinates, heapArray[CurrentSize].Value); // newNode.Value.Coordinates, newNode);

            CascadeUp(CurrentSize++);

            return(true);
        }