remove_trial_ht_entry Subroutine

public subroutine remove_trial_ht_entry(hash_val, index, clashes, source_ht)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: hash_val
integer, intent(in) :: index
integer, intent(in) :: clashes
type(trial_hashtable), intent(inout) :: source_ht(:)

Contents

Source Code


Source Code

    subroutine remove_trial_ht_entry(hash_val, index, clashes, source_ht)
        implicit none
        integer, intent(in) :: hash_val, index, clashes
        type(trial_hashtable), intent(inout) :: source_ht(:)
        integer(n_int), allocatable :: tmp(:, :)
        integer :: i, ierr
        character(*), parameter :: this_routine = "remove_trial_ht_entry"

        ! first, copy the contnet of the source_ht entry to a temporary
        ! if there is any to be left
        if (clashes - 1 > 0) then
            allocate(tmp(0:NConEntry, clashes - 1), stat=ierr)
            if (ierr /= 0) call stop_all(this_routine, "Failed allocation")
            do i = 1, index - 1
                tmp(:, i) = source_ht(hash_val)%states(:, i)
            end do
            ! omitting the element to remove
            do i = index + 1, clashes
                tmp(:, i - 1) = source_ht(hash_val)%states(:, i)
            end do

            ! then, reallocate the source_ht entry (if required)
            deallocate(source_ht(hash_val)%states, stat=ierr)
            if (ierr /= 0) call stop_all(this_routine, "Failed deallocation")
            allocate(source_ht(hash_val)%states(0:NConEntry, clashes - 1), stat=ierr)
            if (ierr /= 0) call stop_all(this_routine, "Failed allocation")
            ! and copy the temporary back (if it is non-empty)
            source_ht(hash_val)%states(0:NConEntry, :) = tmp(0:NConEntry, :)
            deallocate(tmp, stat=ierr)
            if (ierr /= 0) call stop_all(this_routine, "Failed deallocation")
        else
            ! just to be sure, allocate with size 0
            deallocate(source_ht(hash_val)%states)
            allocate(source_ht(hash_val)%states(0:NConEntry, 0))
        end if

        ! finally, update the nclashes information
        source_ht(hash_val)%nclash = clashes - 1
    end subroutine remove_trial_ht_entry