change_capacity_i4tuple_callstat Subroutine

private recursive subroutine change_capacity_i4tuple_callstat(dict, new_capacity)

Internal routine for changing the dictionary's capacity.


Type IntentOptional Attributes Name
type(dict_i4tuple_callstat_type), intent(inout) :: dict
integer, intent(in) :: new_capacity


Source Code

      RECURSIVE SUBROUTINE change_capacity_i4tuple_callstat (dict, new_capacity)
      !! Internal routine for changing the dictionary's capacity.
         TYPE(dict_i4tuple_callstat_type), intent(inout)  :: dict
         INTEGER, intent(in) :: new_capacity
         INTEGER :: i, old_size, new_cap
         TYPE(private_item_type_i4tuple_callstat), POINTER  :: item, prev_item
         TYPE(private_item_p_type_i4tuple_callstat), DIMENSION(:), POINTER  :: old_buckets
         new_cap = new_capacity
         ! pre checks
         IF (new_cap > HUGE(i)) THEN
            IF (size(dict%buckets) == HUGE(i)) RETURN ! reached maximum - stay there.
            new_cap = HUGE(i) ! grow as far as possible
         END IF
         IF (new_cap < 1) &
            DBCSR_ABORT("dict_i4tuple_callstat_change_capacity: new_capacity < 1.")
         IF (4*dict%size > 3*new_cap) &
            DBCSR_ABORT("dict_i4tuple_callstat_change_capacity: new_capacity too small.")

         old_size = dict%size
         old_buckets => dict%buckets
         ALLOCATE (dict%buckets(new_capacity))
         dict%size = 0
         do i = 1, size(old_buckets)
            item => old_buckets(i)%p
            do while (ASSOCIATED(item))
               call set_hashed_i4tuple_callstat (dict, item%key, item%value, item%hash)
               prev_item => item
               item => item%next
               deallocate (prev_item)
            end do
         end do

         deallocate (old_buckets)

         IF (old_size /= dict%size) &
            DBCSR_ABORT("dict_i4tuple_callstat_change_capacity: assertion failed")
      END SUBROUTINE change_capacity_i4tuple_callstat