resize_trial_ht Subroutine

public subroutine resize_trial_ht(source_ht, source_ht_size, new_size)

Arguments

Type IntentOptional Attributes Name
type(trial_hashtable), intent(inout), allocatable :: source_ht(:)
integer, intent(inout) :: source_ht_size
integer, intent(in) :: new_size

Contents

Source Code


Source Code

    subroutine resize_trial_ht(source_ht, source_ht_size, new_size)
        ! take a trial_hashtable of size source_ht_size and resize it to new_size
        implicit none
        type(trial_hashtable), allocatable, intent(inout) :: source_ht(:)
        integer, intent(inout) :: source_ht_size
        integer, intent(in) :: new_size

        type(trial_hashtable), allocatable :: tmp(:)
        integer :: ierr, i

        ! no support for shrinking down hashtables
        if (source_ht_size > new_size) return

        if (allocated(source_ht)) then
            ! if the source_ht contains data, save it
            if (source_ht_size > 0) then
                allocate(tmp(source_ht_size), stat=ierr)
                tmp = source_ht
            end if
            ! if source_ht is already there, deallocate it
            deallocate(source_ht)
        end if

        ! now, create the new source_ht
        allocate(source_ht(new_size), stat=ierr)
        ! if we saved data, move it now
        if (allocated(tmp)) then
            source_ht(1:source_ht_size) = tmp(1:source_ht_size)
            deallocate(tmp)
        end if

        ! then, fill up the newly created entries with empty lists
        do i = source_ht_size + 1, new_size
            source_ht(i)%nclash = 0
        end do

        ! finally, declare that source_ht is now of size new_size
        source_ht_size = new_size
    end subroutine resize_trial_ht