add_hash_table_entry Subroutine

public pure subroutine add_hash_table_entry(hash_table, ind, hash_val)

Arguments

Type IntentOptional Attributes Name
type(ll_node), intent(inout), pointer :: hash_table(:)
integer, intent(in) :: ind
integer, intent(in) :: hash_val

Contents

Source Code


Source Code

    pure subroutine add_hash_table_entry(hash_table, ind, hash_val)

        ! Add an entry of ind into hash_table at an index specified by hash_val.

        type(ll_node), pointer, intent(inout) :: hash_table(:)
        integer, intent(in) :: ind
        integer, intent(in) :: hash_val

        type(ll_node), pointer :: temp_node

        ! Point to the start of the linked list corresponding to hash_val.
        temp_node => hash_table(hash_val)
        if (temp_node%ind == 0) then
            ! If here then this linked list is empty.
            ! Just need to add the index to the hash table and exit.
            temp_node%ind = ind
        else
            ! If here then there is at least one entry in this linked list.
            ! Cycle to the end of the linked list, and add this new entry on
            ! the end.
            do while (associated(temp_node%next))
                temp_node => temp_node%next
            end do
            allocate(temp_node%next)
            nullify (temp_node%next%next)
            temp_node%next%ind = ind
        end if

        nullify (temp_node)

    end subroutine add_hash_table_entry