整数バッファへ値を追加し、必要なら容量を拡張する。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=i32), | intent(inout), | allocatable | :: | buf(:) | ||
| integer(kind=i32), | intent(inout) | :: | n_used |
使用中要素数。 |
||
| integer(kind=i32), | intent(inout) | :: | capacity |
使用中要素数。 確保容量。 |
||
| integer(kind=i32), | intent(in) | :: | value |
追加する値。 |
subroutine append_i32_buffer(buf, n_used, capacity, value) integer(i32), allocatable, intent(inout) :: buf(:) integer(i32), intent(inout) :: n_used, capacity integer(i32), intent(in) :: value integer(i32), allocatable :: tmp(:) integer(i32) :: new_capacity if (n_used >= capacity) then new_capacity = max(capacity*2_i32, capacity + 32_i32) allocate (tmp(new_capacity)) tmp = 0_i32 if (n_used > 0_i32) tmp(1:n_used) = buf(1:n_used) call move_alloc(tmp, buf) capacity = new_capacity end if n_used = n_used + 1_i32 buf(n_used) = value end subroutine append_i32_buffer