linked_node Derived Type

type, public, extends(node) :: linked_node

type~~linked_node~~InheritsGraph type~linked_node linked_node type~linked_node->type~linked_node next type~node node type~node->type~linked_node type~container container type~container->type~node contents
Help


A node which, in addition to holding a value, points at another (the next) linked_node or descendent type. This type can be built up into a chain, allowing a linked list to be formed.

It is not anticipated that the linked_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.

Inherited By

type~~linked_node~~InheritedByGraph type~linked_node linked_node type~linked_node->type~linked_node next type~bidir_node bidir_node type~linked_node->type~bidir_node type~bidir_node->type~bidir_node prev
Help

Components

TypeVisibility AttributesNameInitial
class(linked_node), private, pointer:: next=> null()

The next node in the chain.


Type-Bound Procedures

procedure, public :: has_next

Checks whether this node points to another one

  • private elemental function has_next(this)

    Arguments

    Type IntentOptional AttributesName
    class(linked_node), intent(in) :: this

    Return Value logical

    Description

    Author
    Chris MacMackin
    Date
    February 2016

    Returns whether or not this node points at another one, forming a chain.

procedure, public :: get_next

Returns the next node in the chain if it exists.

  • private function get_next(this)

    Arguments

    Type IntentOptional AttributesName
    class(linked_node), intent(in) :: this

    Return Value class(linked_node), pointer

    Description

    Author
    Chris MacMackin
    Date
    February 2016

    Returns a pointer to the node which this ones points to, i.e. the next node in the chain. If this node does not point at another one, then a null pointer is returned.

procedure, public :: set_next

Sets the next node in the chain.

  • private subroutine set_next(this, new_next, deallocate_old)

    Arguments

    Type IntentOptional AttributesName
    class(linked_node), intent(inout) :: this
    class(linked_node), intent(in), pointer:: new_next

    The node which will now be next in the chain.

    logical, intent(in), optional :: deallocate_old

    Whether to deallocate (rather than just nullify) any existing subsequent nodes in the chain. Defaults to .false..

    Description

    Author
    Chris MacMackin
    Date
    February 2016

    Sets the node which this one points to (i.e. sets the next node in the chain). If this node already points to another one, the pointer will, by default, be nullified. This may result in a memory leak. Optionally, by setting deallocate_old=.true., the next 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 next node.

procedure, public :: unset_next

Sets this node not to point at any others, severing the chain.

  • private subroutine unset_next(this, deallocate_old)

    Arguments

    Type IntentOptional AttributesName
    class(linked_node), intent(inout) :: this
    logical, intent(in), optional :: deallocate_old

    Whether to deallocate (rather than just nullify) any existing subsequent nodes in the chain. Defaults to .false..

    Description

    Author
    Chris MacMackin
    Date
    February 2016

    Unsets the pointer to the next 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 next 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 next node.

Source Code

  type, extends(node), public :: linked_node
    !* Author: Chris MacMackin
    !  Date: February 2016
    !
    ! A node which, in addition to holding a value, points at another
    ! (the next) linked_node or descendent type. This type can be built
    ! up into a chain, allowing a linked list to be formed.
    ! 
    ! It is not anticipated that the linked_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(linked_node), pointer :: next => null() !! The next node in the chain.
  contains
    procedure :: has_next
      !! Checks whether this node points to another one 
    procedure :: get_next
      !! Returns the next node in the chain if it exists.
    procedure :: set_next
      !! Sets the next node in the chain.
    procedure :: unset_next
      !! Sets this node not to point at any others, severing the chain.
  end type linked_node