src/NodeHeap.cpp
// Sorts the heap from the bottom - i.e the latest element inputted. Generally called in the
// addElement method. 
Sorts the heap from the bottom - i.e the latest element inputted. Generally called in the
addElement method.
Sorts the heap from the bottom - i . e the latest element inputted . Generally called in the addElement method .
void sortUp(NodeHeap& heap) {
        int item_idx = heap.fCosts.size() - 1;
        int parent_idx = (item_idx-1)/2;
        while (true) {
            int item_cost = heap.fCosts[item_idx];
            int parent_cost = heap.fCosts[parent_idx];
            if (item_cost < parent_cost) {
                std::iter_swap(heap.fCosts.begin() + item_idx, heap.fCosts.begin() + parent_idx);
                std::iter_swap(heap.coordinates.begin() + item_idx, heap.coordinates.begin() + parent_idx);
                heap.indices[heap.coordinates[item_idx].x][heap.coordinates[item_idx].y] = item_idx;
                heap.indices[heap.coordinates[parent_idx].x][heap.coordinates[parent_idx].y] = parent_idx;
                item_idx = parent_idx;
            } else {
                break;
            }
            parent_idx = (parent_idx-1)/2;
        }
    }
void sortUp ( NodeHeap & heap ) { int item_idx = heap . fCosts . size ( ) - 1 ; int parent_idx = ( item_idx - 1 ) / 2 ; while ( true ) { int item_cost = heap . fCosts [ item_idx ] ; int parent_cost = heap . fCosts [ parent_idx ] ; if ( item_cost < parent_cost ) { std :: iter_swap ( heap . fCosts . begin ( ) + item_idx , heap . fCosts . begin ( ) + parent_idx ) ; std :: iter_swap ( heap . coordinates . begin ( ) + item_idx , heap . coordinates . begin ( ) + parent_idx ) ; heap . indices [ heap . coordinates [ item_idx ] . x ] [ heap . coordinates [ item_idx ] . y ] = item_idx ; heap . indices [ heap . coordinates [ parent_idx ] . x ] [ heap . coordinates [ parent_idx ] . y ] = parent_idx ; item_idx = parent_idx ; } else { break ; } parent_idx = ( parent_idx - 1 ) / 2 ; } }
Sorts the heap from the bottom - i.e the latest element inputted.
Sorts the heap from the bottom - i . e the latest element inputted .
// Keep checking the parent and comparing the value with it. If the parent is larger than the // current element then swap their positions and indices.  //std::cout << "Start index: " << item_idx << std::endl; //std::cout << "Parent index: " << parent_idx << std::endl; //std::cout << "The new item has a smaller fcost! Swapping values " << std::endl; // Swap the values.  // Swap the index values.  // Break out of the loop if the value is larger than it's parent.  // Update the parent index. 