An abstract data type representing a list. This is a fully dynamic means of storing data of a single type and comes with many advanced type-bound procedures for manipulating said data. This derived type aims to provide many of the same features found in lists in higher-level languages such as Python
Add an item to the end of the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
class(*), | intent(in) | :: | item | Item to be appended to list |
Get the item at the specified index
Set the specified element to the specified value
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | element | The index (starting from 1) of the element whose value is to be set. |
||
class(*), | intent(in) | :: | item | The value to store in the specified element |
Set the specified elements to the specified values
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in), | dimension(:) | :: | elements | The indices (starting from 1) of the elements whose values are to be set. |
|
class(*), | intent(in), | dimension(:) | :: | items | The values to be stored in the specified elements. Each item
is placed in the element specified by the integer in the
corresponding position in the array |
Set the value of one or more elements in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | element | The index (starting from 1) of the element whose value is to be set. |
||
class(*), | intent(in) | :: | item | The value to store in the specified element |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in), | dimension(:) | :: | elements | The indices (starting from 1) of the elements whose values are to be set. |
|
class(*), | intent(in), | dimension(:) | :: | items | The values to be stored in the specified elements. Each item
is placed in the element specified by the integer in the
corresponding position in the array |
Get the index of the first occurrence of this item in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
class(*), | intent(in) | :: | item |
Position of the first occurrence of item
in list
Get the index of the last occurrence of this item in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
class(*), | intent(in) | :: | item |
Position of the last occurrence of item
in list
Get the indices of all occurrences of this item in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
class(*), | intent(in) | :: | item |
Positions of the all occurrences of item
in list
Returns a list containing the items with indices in the specified range
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
integer, | intent(in) | :: | start_element | The index of the first element in the slice to be returned |
||
integer, | intent(in) | :: | end_element | The index of the last element in the slice to be returned |
A list containing the elements within the slice.
Perform the provided procedure on each element of the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
procedure(action_sub) | :: | action | A procedure to act on each element of the list |
Add the item to the specified position in the list, moving all succeeding elements forward by one position
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | position | The location at which the new element will be placed |
||
class(*), | intent(in) | :: | item | The value to be placed in the list |
Remove the first occurrence of the specified item from the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
class(*), | intent(in) | :: | item | An item, the first occurrence of which will be removed from the list |
Remove the last occurrence of the specified item from the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
class(*), | intent(in) | :: | item | An item, the last occurrence of which will be removed from the list |
Remove the all occurrences of the specified item from the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
class(*), | intent(in) | :: | item | An item, all occurrences of which will be removed from the list |
Remove the item from the list at the specified index
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | element | The position of the element to be deleted from the list |
Remove the items from the list at the specified indices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in), | dimension(:) | :: | element | The positions of the elements to be deleted from the list |
Remove the items from the list within the specified slice
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | start_element | Index of the first element in the slice to be deleted |
||
integer, | intent(in) | :: | end_element | Index of the last element in the slice to be deleted |
Remove one or more elements from the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | element | The position of the element to be deleted from the list |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in), | dimension(:) | :: | element | The positions of the elements to be deleted from the list |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
integer, | intent(in) | :: | start_element | Index of the first element in the slice to be deleted |
||
integer, | intent(in) | :: | end_element | Index of the last element in the slice to be deleted |
Returns .true.
if the specified item is present in the list.
Sorts the list in place using the provided comparison procedure
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(inout) | :: | this | |||
procedure(comparison_func) | :: | comparison | A procedure which evaluates whether a container object is less than, equal to, or greater than another |
Returns the smallest item in the list as determined using the provided comparison procedure
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
procedure(comparison_func) | :: | comparison | A procedure which evaluates whether a container object is less than, equal to, or greater than another |
The smallest item in the list, as determined by the
comparison
function
Returns the largest item in the list as determined using the provided comparison procedure
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
procedure(comparison_func) | :: | comparison | A procedure which evaluates whether a container object is less than, equal to, or greater than another |
The largest item in the list, as determined by the
comparison
function
Returns the item in the list for which the provided subtraction procedure returns the smallest absolute value
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
class(*), | intent(in) | :: | item | The value which those in the list are being compared to |
||
procedure(subtraction_func) | :: | subtraction | A function determining the magnitude of the difference between two items |
The value from the list which, when passed to subtraction
with item
as the other argument, returns the smallest value
Returns an item representing the sum as determined by iteratively applying the provided addition procedure to all elements in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
procedure(addition_func) | :: | addition | A procedure performing addition between two container objects and returning the result in another container |
A container holding the sum of all of the items held within this list
Returns a list containing all elements from this list for which
the provided test procedure returns .true.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this | |||
procedure(test_func) | :: | test | A test for which the values that pass will be returned in a new list |
Contains those items in this list for which test
returns
.true.
Returns an array of containers holding the contents of this list.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(list), | intent(in) | :: | this |
An array of container objects holding the contents of this list
type, abstract, extends(deque), public :: list
!* Author: Chris MacMackin
! Date: March 2016
!
! An abstract data type representing a list. This is a fully dynamic
! means of storing data of a single type and comes with many advanced
! type-bound procedures for manipulating said data. This derived type
! aims to provide many of the same features found in lists in
! higher-level languages such as Python
!
contains
procedure(append_sub), deferred :: append
!! Add an item to the end of the list
procedure(get_func), deferred :: get
!! Get the item at the specified index
procedure(set_single_sub), deferred, private :: set_single
!! Set the specified element to the specified value
procedure(set_multiple_sub), deferred, private :: set_multiple
!! Set the specified elements to the specified values
generic :: set => set_single, set_multiple
!! Set the value of one or more elements in the list
procedure(get_index_func), deferred :: get_index
!! Get the index of the first occurrence of this item in the list
procedure(get_last_index_func), deferred :: get_last_index
!! Get the index of the last occurrence of this item in the list
procedure(get_indices_func), deferred :: get_indices
!! Get the indices of all occurrences of this item in the list
procedure(slice_func), deferred :: slice
!! Returns a list containing the items with indices in the
!! specified range
procedure(foreach_sub), deferred :: foreach
!! Perform the provided procedure on each element of the list
procedure(insert_sub), deferred :: insert
!! Add the item to the specified position in the list, moving
!! all succeeding elements forward by one position
procedure(remove_sub), deferred :: remove
!! Remove the first occurrence of the specified item from the list
procedure(remove_last_sub), deferred :: remove_last
!! Remove the last occurrence of the specified item from the list
procedure(remove_all_sub), deferred :: remove_all
!! Remove the all occurrences of the specified item from the list
procedure(delete_single_sub), deferred, private :: delete_single
!! Remove the item from the list at the specified index
procedure(delete_multiple_sub), deferred, private :: delete_multiple
!! Remove the items from the list at the specified indices
procedure(delete_slice_sub), deferred, private :: delete_slice
!! Remove the items from the list within the specified slice
generic :: delete => delete_single, delete_multiple, delete_slice
!! Remove one or more elements from the list
procedure(has_func), deferred :: has
!! Returns `.true.` if the specified item is present in the list.
procedure(sort_sub), deferred :: sort
!! Sorts the list in place using the provided comparison procedure
procedure(min_func), deferred :: min
!! Returns the smallest item in the list as determined using the
!! provided comparison procedure
procedure(max_func), deferred :: max
!! Returns the largest item in the list as determined using the
!! provided comparison procedure
procedure(nearest_func), deferred :: nearest
!! Returns the item in the list for which the provided subtraction
!! procedure returns the smallest absolute value
procedure(sum_func), deferred :: sum
!! Returns an item representing the sum as determined by
!! iteratively applying the provided addition procedure to all
!! elements in the list
procedure(filter_func), deferred :: filter
!! Returns a list containing all elements from this list for which
!! the provided test procedure returns `.true.`
procedure(to_array_func), deferred :: to_array
!! Returns an array of containers holding the contents of this
!! list.
end type list