change_capacity_str_i4 Subroutine

private recursive subroutine change_capacity_str_i4(dict, new_capacity)

Internal routine for changing the dictionary's capacity.

Arguments

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

Source Code

      RECURSIVE SUBROUTINE change_capacity_str_i4 (dict, new_capacity)
      !! Internal routine for changing the dictionary's capacity.
         TYPE(dict_str_i4_type), intent(inout)  :: dict
         INTEGER, intent(in) :: new_capacity
         INTEGER :: i, old_size, new_cap
         TYPE(private_item_type_str_i4), POINTER  :: item, prev_item
         TYPE(private_item_p_type_str_i4), 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_str_i4_change_capacity: new_capacity < 1.")
         IF (4*dict%size > 3*new_cap) &
            DBCSR_ABORT("dict_str_i4_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_str_i4 (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_str_i4_change_capacity: assertion failed")
      END SUBROUTINE change_capacity_str_i4