Append pointer to dealloc list using count-based tracking (O(1) amortized)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(array_ptr), | intent(inout), | allocatable | :: | list(:) | ||
| integer, | intent(inout) | :: | count | |||
| type(array_type), | intent(in), | target | :: | ptr |
subroutine dealloc_list_append(list, count, ptr) !! Append pointer to dealloc list using count-based tracking (O(1) amortized) implicit none type(array_ptr), allocatable, intent(inout) :: list(:) integer, intent(inout) :: count type(array_type), intent(in), target :: ptr integer :: cap if(.not. allocated(list))then allocate(list(diffstruc__init_map_cap)) count = 0 end if cap = size(list) if(count .ge. cap)then ! Double capacity block type(array_ptr) :: tmp(cap) tmp = list(1:cap) deallocate(list) allocate(list(cap * 2)) list(1:cap) = tmp end block end if count = count + 1 list(count)%p => ptr end subroutine dealloc_list_append