A node which, in addition to holding a value, points at two other (the previous and next) bidir_node objects or objects of a descendent type. This type can be built up into a chain, allowing a doubly-linked list to be formed.
It is not anticipated that the bidir_node type, or any types extending it, will be handled directly by end users of FIAT; they are meant for internal use within this package. As such, care must be taken when using certain methods (see below) to avoid memory leaks or segfaults.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
class(bidir_node), | private, | pointer | :: | prev | => | null() |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(bidir_node), | intent(in) | :: | this |
Returns whether or not this node points to a previous one, forming a chain in the backwards direction.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(bidir_node), | intent(in) | :: | this |
Returns a pointer to the previous node in the chain. If this node does not point at a previous one one, then a null pointer is returned.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(bidir_node), | intent(inout) | :: | this | |||
class(bidir_node), | intent(in), | pointer | :: | new_prev | The node which will now be previous in the chain. |
|
logical, | intent(in), | optional | :: | deallocate_old | Whether to deallocate (rather than just nullify) any existing
previous nodes in the chain. Defaults to |
Sets the pointer to the previous node in the chain. If this node
already points to a previous one, the pointer will, by default, be
nullified. This may result in a memory leak. Optionally, by
setting deallocate_old=.true.
, the previous node (and all nodes
it points to) can be deallocated. This may result in a segfault if
another part of the program tries to access the former previous
node. The new previous node will not automatically be set to have
this one as the next, with the same rules applied to deallocation.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(bidir_node), | intent(inout) | :: | this | |||
logical, | intent(in), | optional | :: | deallocate_old | Whether to deallocate (rather than just nullify) any existing
p nodes in the chain. Defaults to |
Unsets the pointer to the previous node in the chain, severing it.
By default, the pointer is only nullified. This may result in a
memory leak. Optionally, by setting deallocate_old=.true.
, the
previous node (and all previous nodes it points to) can be
deallocated. This may result in a segfault if another part of the
program tries to access the former previous node.
type, extends(linked_node), public :: bidir_node
!* Author: Chris MacMackin
! Date: February 2016
!
! A node which, in addition to holding a value, points at two other
! (the previous and next) bidir_node objects or objects of a
! descendent type. This type can be built up into a chain, allowing
! a doubly-linked list to be formed.
!
! It is not anticipated that the bidir_node type, or any types
! extending it, will be handled directly by end users of FIAT; they
! are meant for internal use within this package. As such, care must
! be taken when using certain methods (see below) to avoid memory
! leaks or segfaults.
!
private
class(bidir_node), pointer :: prev => null()
contains
procedure :: has_prev
procedure :: get_prev
procedure :: set_prev
procedure :: unset_prev
end type bidir_node