A generic list.
It uses an unlimited polymorphic class(*) pointer variable to allow it
to contain any type of data. The key can be an integer, string, or
any user-defined key_class.
list constructor.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| logical, | intent(in) | :: | case_sensitive |
if true, then string key searches are case sensitive. |
internal function for traversing all nodes in a list
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(node), | pointer | :: | me | |||
| logical, | intent(out) | :: | done |
set to true to stop traversing |
for traversing all keys in a list
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(*), | intent(in) | :: | key |
the node key |
||
| class(*), | pointer | :: | value |
pointer to the node value |
||
| logical, | intent(out) | :: | done |
set to true to stop traversing |
a node in the linked list. This is the container to
the unlimited polymorphic value variable.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| class(*), | private, | allocatable | :: | key |
the key (can be integer, string, or key_class) |
||
| class(*), | private, | pointer | :: | value | => | null() |
the data to hold |
| logical, | private | :: | destroy_on_delete | = | .true. |
if true, value pointer is deallocated when it is removed from the list, or the list is destroyed. If false, it is only nullified. |
|
| type(node), | private, | pointer | :: | next | => | null() |
the next one in the list |
| type(node), | private, | pointer | :: | previous | => | null() |
the previous one in the list |
| procedure, public :: destroy => destroy_node_data | ../../ deallocate value |
| procedure, public :: get_data => get_node_data | ../../ get data from a node |
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 |
| private function initialize_list (case_sensitive) | list constructor. |
| final :: list_finalizer |
| 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 |
| 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 |
| procedure, private :: keys_equal | ../../ for testing key string equality |
Returns true if the key is present in the list
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| class(*), | intent(in) | :: | key |
list constructor.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| logical, | intent(in) | :: | case_sensitive |
if true, then string key searches are case sensitive. |
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 |
Convert a string to uppercase.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
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. |
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. |
destroy the data in the node.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(node), | intent(inout) | :: | me |
just a wrapper for destroy_list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(list), | intent(inout) | :: | me |
destroy the list (traverses from head to tail)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me |
destroy the node (and subsequent ones in the list).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(node), | pointer | :: | me |
Remove an item from the list (given the key).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| class(*), | intent(in) | :: | key |
Get the data from a node
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(node), | intent(in) | :: | me | |||
| class(*), | intent(out), | pointer | :: | value |
Returns a pointer to the data stored in the list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(in) | :: | me | |||
| class(*), | intent(in) | :: | key | |||
| class(*), | intent(out), | pointer | :: | value |
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 |
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. |