sort_keys Subroutine

private pure subroutine sort_keys(a)

Sort keys, increasing (a bottom-up merge sort).

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(inout) :: a(:)

the keys


Called by

proc~~sort_keys~~CalledByGraph proc~sort_keys sort_keys proc~unique_edges unique_edges proc~unique_edges->proc~sort_keys proc~set_faces Polyhedron%set_faces proc~set_faces->proc~unique_edges proc~set_triangles Polyhedron%set_triangles proc~set_triangles->proc~unique_edges

Source Code

    pure subroutine sort_keys(a)
        integer(int64), intent(inout) :: a(:)               !! the keys
        integer(int64), allocatable :: b(:)
        integer :: n, width, lo, mid, hi, i, j, k
        n = size(a)
        allocate(b(n))
        width = 1
        do while (width < n)
            do lo = 1, n, 2 * width
                mid = min(lo + width, n + 1)
                hi = min(lo + 2 * width, n + 1)
                i = lo
                j = mid
                do k = lo, hi - 1
                    if (i < mid .and. (j >= hi .or. a(min(i, n)) <= a(min(j, n)))) then
                        b(k) = a(i)
                        i = i + 1
                    else
                        b(k) = a(j)
                        j = j + 1
                    end if
                end do
            end do
            a = b
            width = 2 * width
        end do
    end subroutine sort_keys