-
Notifications
You must be signed in to change notification settings - Fork 0
Add checks on work
and iwork
#5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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".
Done.
I am not sure that I understand your comment. Here is the structure in ! 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:
Or do I miss something? |
You are right there is no assumption that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks Good!
Thanks. From my side, you can merge it. |
I think I have merged. |
@wclodius2 Here are some additions for checks on
work
andiwork