dfa_state_node__reallocate_transition_forward Subroutine

private pure subroutine dfa_state_node__reallocate_transition_forward(self)

This subroutine performs allocating initial or additional transition arrays.

Note

Note that the return value of the size intrinsic function for an unallocated array is undefined.

Type Bound

dfa_state_node_t

Arguments

Type IntentOptional Attributes Name
class(dfa_state_node_t), intent(inout) :: self

Source Code

   pure subroutine dfa_state_node__reallocate_transition_forward(self)
      implicit none
      class(dfa_state_node_t), intent(inout) :: self

      type(dfa_transition_t), allocatable :: tmp(:)
      integer :: siz, j
      integer :: new_part_begin, new_part_end

      siz = 0

      !! @note Note that the return value of the `size` intrinsic function for an unallocated array is undefined.

      if (self%initialized .and. allocated(self%transition)) then
         ! If already initialized, copy the transitions to a temporary array `tmp`.
         siz = size(self%transition, dim=1)
         call move_alloc(self%transition, tmp)
      else
         ! If not yet initialized, call init_tra_top procedure.
         siz = 0
         call self%init_tra_top(DFA_INIT_TRANSITION_TOP)
      end if

      self%alloc_count_f = self%alloc_count_f + 1 ! Increment

      new_part_begin = siz + 1
      new_part_end = DFA_TRANSITION_UNIT * 2**self%alloc_count_f

      allocate(self%transition(DFA_TRANSITION_BASE:new_part_end))

      ! Copy registered data
      if(allocated(tmp)) self%transition(DFA_TRANSITION_BASE:siz) = tmp(DFA_TRANSITION_BASE:siz) 

      ! Initialize the new part of the array.
      self%transition(new_part_begin:new_part_end)%own_j = [(j, j=new_part_begin, new_part_end)]
      self%initialized = .true.
   end subroutine dfa_state_node__reallocate_transition_forward