List of integers with a given maximum fixed size The first index is always 1, and filled up to n_used It contains routines for managing the list
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=i4), | public | :: | n | = | 0 | ||
integer(kind=i4), | public | :: | n_used | = | 0 | ||
integer(kind=i4), | public, | allocatable | :: | list(:) |
Finalize the list For that, we need to deallocate the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dynamical_list_t), | intent(inout) | :: | this |
Initialize an empty list with a given size Input: n - the size of the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | n |
Reset the list For that, we only need to set n_used to 0
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this |
Print the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(in) | :: | this |
Expand the list to a new size
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | new_size |
Trim the list to the number of used elements
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this |
Returns the last element of the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(in) | :: | this |
Count the number of times an element appears in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(in) | :: | this | |||
integer(kind=i4), | intent(in) | :: | element |
Add an element to the list It assumes that the list is already allocated The element is added to the end of the list Input: element - the element to add
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | element |
Add an array to the list It will initialize the list if it is not already allocated, with the size of the array Input: array - the array to add
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | array(:) |
Remove an element from the list It will replace the element at the given position with the last element WARNING: This can change the position of the elements in the list, DO NOT use sequentially with the original indexes, that are not updated after each removal Input: position - the position of the element to remove
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | position |
Remove a list of elements from the list It will replace the elements in the list with the last elements For that, we need to sort the positions It is safe because the elements are removed in reverse order Input: position_arr - the array of positions to remove Dependency: stdlib_sorting
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | position_arr(:) |
Remove a range of elements from the list It will replace the elements in the range with the last elements This is safe because the elements are removed in reverse order Input: ini_position - the initial position of the range to remove fin_position - the final position of the range to remove
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | ini_position | |||
integer(kind=i4), | intent(in) | :: | fin_position |
Create from array, if it is not already allocated Input: array - the array to create the list from
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | array(:) |
Returns the element at the given position Input: position - the position of the element to return
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(in) | :: | this | |||
integer(kind=i4), | intent(in) | :: | position |
Return the sum of the elements in the list It sums only the valid elements
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dynamical_list_t), | intent(in) | :: | this |