mod_matrix_row Module

Module that contains the implementation of a single row of nodes in the linked-list matrix representation.



Contents


Derived Types

type, public :: row_t

Linked list for a given row index, contains the column values

Components

TypeVisibilityAttributesNameInitial
integer, public :: nb_elements

number of elements in linked list

type(node_t), public, pointer:: head

pointer to head (first element added)

type(node_t), public, pointer:: tail

pointer to tail (last element added)

Type-Bound Procedures

procedure, public :: add_node
procedure, public :: get_node
procedure, public :: delete_row
procedure, public :: delete_node_from_row
procedure, private :: create_first_node
procedure, private :: append_node

Functions

public pure function new_row() result(row)

Constructor for a new row, initialises the linked list datastructure and sets the current head and tail pointers to null().

Arguments

None

Return Value type(row_t)

private function get_node(this, column) result(node)

Returns a pointer to the node corresponding to the given column. Returns a nullified pointer if no node containing the given column index was found.

Arguments

TypeIntentOptionalAttributesName
class(row_t), intent(in) :: this

type instance

integer, intent(in) :: column

column index

Return Value type(node_t),pointer

the node with a column value that matches column


Subroutines

private subroutine add_node(this, column, element)

Adds a new node to the linked list with a given column index and value.

Arguments

TypeIntentOptionalAttributesName
class(row_t), intent(inout) :: this

type instance

integer, intent(in) :: column

column position of the element

class(*), intent(in) :: element

the element to be added

private pure subroutine create_first_node(this, column, element)

Subroutine to add the first node to the linked list. Allocates a new node and sets both the head and tail to this node.

Arguments

TypeIntentOptionalAttributesName
class(row_t), intent(inout) :: this

type instance

integer, intent(in) :: column

column position of element

class(*), intent(in) :: element

the element to be added

private subroutine append_node(this, column, element)

Subroutine to append a new node to an already existing list of nodes. A new node is created, appended, and the tail is updated.

Arguments

TypeIntentOptionalAttributesName
class(row_t), intent(inout) :: this

type instance

integer, intent(in) :: column

column position of element

class(*), intent(in) :: element

the element to be added

private subroutine delete_node_from_row(this, column)

Deletes a given node from the current row.

Arguments

TypeIntentOptionalAttributesName
class(row_t), intent(inout) :: this

type instance

integer, intent(in) :: column

column index of node to be deleted

private pure subroutine delete_row(this)

Deletes a given linked list row by recursively iterating over all nodes. Nullifies the pointers and deallocates the elements.

Arguments

TypeIntentOptionalAttributesName
class(row_t), intent(inout) :: this

type instance