Skip to content

Conversation

@jvdp1
Copy link

@jvdp1 jvdp1 commented Jun 1, 2021

@wclodius2 Here are some additions for checks on work and iwork

Copy link
Owner

@wclodius2 wclodius2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change "work array too small" to "work array is too small". Technically in stdlib_sorting_sort_index iwork can be present independent of work, but you assume that iwork is present only if work is present. The error stops for iwork should be "iwork array is too small" not "work array too small".

@jvdp1
Copy link
Author

jvdp1 commented Jun 1, 2021

Change "work array too small" to "work array is too small". .... The error stops for iwork should be "iwork array is too small" not "work array too small".

Done.

Technically in stdlib_sorting_sort_index iwork can be present independent of work, but you assume that iwork is present only if work is present.

I am not sure that I understand your comment. Here is the structure in stdlib_sorting_sort_index:

! If necessary allocate buffers to serve as scratch memory.
        if ( present(work) ) then
            if ( size(work, kind=int_size) < array_size/2 ) then
                error stop "work array is too small."
            end if
            if ( present(iwork) ) then
                if ( size(iwork, kind=int_size) < array_size/2 ) then
                    error stop "iwork array is too small."
                endif
                call merge_sort( array, index, work, iwork )
            else
                allocate( ibuf(0:array_size/2-1), stat=stat )
                if ( stat /= 0 ) error stop "Allocation of index buffer failed."
                call merge_sort( array, index, work, ibuf )
            end if
        else
            allocate( buf(0:array_size/2-1), stat=stat )
            if ( stat /= 0 ) error stop "Allocation of array buffer failed."
            if ( present(iwork) ) then
                if ( size(iwork, kind=int_size) < array_size/2 ) then
                    error stop "iwork array is too small."
                endif
                call merge_sort( array, index, buf, iwork )
            else
                allocate( ibuf(0:array_size/2-1), stat=stat )
                if ( stat /= 0 ) error stop "Allocation of index buffer failed."
                call merge_sort( array, index, buf, ibuf )
            end if
        end if

This structure allows all possibilities:

  1. (present(work),present(iwork)),
  2. (present(work),.not.present(iwork)),
  3. (.not.present(work), present(iwork)),
  4. (.not.present(work), .not.present(iwork))

Or do I miss something?

@wclodius2
Copy link
Owner

You are right there is no assumption that iwork require work.

Copy link
Owner

@wclodius2 wclodius2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good!

@jvdp1
Copy link
Author

jvdp1 commented Jun 2, 2021

Looks Good!

Thanks. From my side, you can merge it.

@wclodius2 wclodius2 merged commit 1fc5cd9 into wclodius2:sorting2 Jun 2, 2021
@wclodius2
Copy link
Owner

I think I have merged.

@jvdp1 jvdp1 deleted the add_checks1 branch June 2, 2021 18:10
jvdp1 pushed a commit that referenced this pull request Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants