linked list of pointers to polymorphic types.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | private | :: | case_sensitive | = | .true. |
character key lookup is case sensitive |
|
| integer, | private | :: | count | = | 0 |
number of items in the list |
|
| type(node), | private, | pointer | :: | head | => | null() |
the first item in the list |
| type(node), | private, | pointer | :: | tail | => | null() |
the last item in the list |
list constructor.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| logical, | intent(in) | :: | case_sensitive |
if true, then string key searches are case sensitive. |
just a wrapper for destroy_list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(list), | intent(inout) | :: | me |
add a pointer item to the list
Add an item to the list, and associate its pointer to the input value.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| class(*), | intent(in) | :: | key | |||
| class(*), | intent(in), | pointer | :: | value |
value is unlimited polymorphic, so it can be any scalar type. If the type includes pointers or other objects that must be cleaned up when it is destroyed, then it should include a finalizer. |
|
| logical, | intent(in), | optional | :: | destroy_on_delete |
If false, the finalizer will not be called when the item is removed from the list (the pointer will only be nullified, so the caller is responsible for cleaning it up to avoid memory leaks). The default is True. |
add a non-pointer item to the list
Add an item to the end of the list by cloning it.
That is, using a sourced allocation: allocate(newitem, source=value).
A clone is made of the original value, which is not affected.
The list contains only the clone, which will be deallocated (and
finalized if a finalizer is present) when removed from the list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| class(*), | intent(in) | :: | key | |||
| class(*), | intent(in) | :: | value |
get a pointer to an item in the list
destroy the list and deallocate/finalize all the data
destroy the list (traverses from head to tail)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me |
traverse the list are return each key & value
traverse list from head to tail, and call the iterator function for each key.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| procedure(key_iterator) | :: | iterator |
the function to call for each node. |
remove item from the list, given the key
Remove an item from the list (given the key).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| class(*), | intent(in) | :: | key |
remove node from list, given pointer to it
Remove an item from the list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| type(node), | pointer | :: | p |
the item to remove |
traverse each node of the list
traverse list from head to tail, and call the iterator function for each node.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| procedure(iterator_func) | :: | iterator |
the function to call for each node. |
for testing key string equality
Returns true if the two keys are equal.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(in) | :: | me | |||
| class(*), | intent(in) | :: | k1 | |||
| class(*), | intent(in) | :: | k2 |
type,public :: list !! linked list of pointers to polymorphic types. private logical :: case_sensitive = .true. !! character key lookup is case sensitive integer :: count = 0 !! number of items in the list type(node),pointer :: head => null() !! the first item in the list type(node),pointer :: tail => null() !! the last item in the list contains private procedure,public :: add_pointer !! add a pointer item to the list procedure,public :: add_clone !! add a non-pointer item to the list procedure,public :: get => get_data !! get a pointer to an item in the list procedure,public :: destroy => destroy_list !! destroy the list and !! deallocate/finalize all the data procedure,public :: has_key !! if the key is present in the list procedure,public :: traverse !! traverse the list are return each key & value procedure,public :: remove => remove_by_key !! remove item from the list, given the key ! procedures that operate on nodes: procedure,public :: remove_by_pointer !! remove node from list, given pointer to it procedure,public :: get_node !! get a pointer to a node in the list procedure,public :: traverse_list !! traverse each node of the list !private routines: procedure :: keys_equal !! for testing key string equality final :: list_finalizer end type list