src/NodeHeap.cpp
// Sorts the heap from the top - the element in position 0. 
// Generally called in the removeFirst method. 
Sorts the heap from the top - the element in position 0.
Generally called in the removeFirst method.
Sorts the heap from the top - the element in position 0 . Generally called in the removeFirst method .
void sortDown(NodeHeap& heap) {
        int element = heap.fCosts.front();
        int index = 0;
        while (true) {
            int childIndexLeft = (index * 2) + 1;
            int childIndexRight = (index * 2) + 2;
            int swapIndex = 0;
            if (isInBounds(childIndexLeft, heap.fCosts.size())) {
                swapIndex = childIndexLeft;
                if (isInBounds(childIndexRight, heap.fCosts.size())) {
                    if (heap.fCosts[childIndexLeft] > heap.fCosts[childIndexRight]) {
                        swapIndex = childIndexRight;
                    }
                }
                if (element > heap.fCosts[swapIndex]) {
                    std::iter_swap(heap.fCosts.begin() + index, heap.fCosts.begin() + swapIndex);
                    std::iter_swap(heap.coordinates.begin() + index, heap.coordinates.begin() + swapIndex);
                    heap.indices[heap.coordinates[swapIndex].x][heap.coordinates[swapIndex].y] = swapIndex;
                    heap.indices[heap.coordinates[index].x][heap.coordinates[index].y] = index;
                    index = swapIndex;
                } else {
                    return;
                }
            } else {
                return;
            }
        }
    }
void sortDown ( NodeHeap & heap ) { int element = heap . fCosts . front ( ) ; int index = 0 ; while ( true ) { int childIndexLeft = ( index * 2 ) + 1 ; int childIndexRight = ( index * 2 ) + 2 ; int swapIndex = 0 ; if ( isInBounds ( childIndexLeft , heap . fCosts . size ( ) ) ) { swapIndex = childIndexLeft ; if ( isInBounds ( childIndexRight , heap . fCosts . size ( ) ) ) { if ( heap . fCosts [ childIndexLeft ] > heap . fCosts [ childIndexRight ] ) { swapIndex = childIndexRight ; } } if ( element > heap . fCosts [ swapIndex ] ) { std :: iter_swap ( heap . fCosts . begin ( ) + index , heap . fCosts . begin ( ) + swapIndex ) ; std :: iter_swap ( heap . coordinates . begin ( ) + index , heap . coordinates . begin ( ) + swapIndex ) ; heap . indices [ heap . coordinates [ swapIndex ] . x ] [ heap . coordinates [ swapIndex ] . y ] = swapIndex ; heap . indices [ heap . coordinates [ index ] . x ] [ heap . coordinates [ index ] . y ] = index ; index = swapIndex ; } else { return ; } } else { return ; } } }
Sorts the heap from the top - the element in position 0.
Sorts the heap from the top - the element in position 0 .
// Get the left and right children.  // Check if the left child is in bounds.  // Check if the right child is in bounds.  // Check if the right child has higher priority to the left child.  // If the element has less priority than its child then swap the values.  // Swap the values. // Replace their indices. // Update the index and keep going. 