reserve_pool Subroutine

private subroutine reserve_pool(this, needed)

Ensure the packed key pool holds at least needed characters.

Arguments

Type IntentOptional Attributes Name
class(hash_map_t), intent(inout) :: this
integer(kind=default_int), intent(in) :: needed

Called by

proc~~reserve_pool~~CalledByGraph proc~reserve_pool reserve_pool proc~hash_map_insert hash_map_t%hash_map_insert proc~hash_map_insert->proc~reserve_pool

Variables

Type Visibility Attributes Name Initial
character(len=1), private, allocatable :: fresh(:)
integer(kind=default_int), private :: i
integer(kind=default_int), private :: new_cap

Source Code

   subroutine reserve_pool(this, needed)
      !! Ensure the packed key pool holds at least `needed` characters.
      class(hash_map_t), intent(inout) :: this
      integer(default_int), intent(in) :: needed

      character(len=1), allocatable :: fresh(:)
      integer(default_int) :: new_cap, i

      if (needed <= this%pool_cap) return

      new_cap = max(this%pool_cap, MIN_POOL)
      do while (new_cap < needed)
         new_cap = new_cap*2
      end do

      allocate (fresh(new_cap))
      do i = 1, this%pool_used
         fresh(i) = this%key_pool(i)
      end do

      deallocate (this%key_pool)
      call move_alloc(fresh, this%key_pool)
      this%pool_cap = new_cap
   end subroutine reserve_pool