dm_hash_table Module

Very basic hash table implementation for a modest number of elements that stores only pointers to values.


Uses

  • module~~dm_hash_table~~UsesGraph module~dm_hash_table dm_hash_table module~dm_error dm_error module~dm_hash_table->module~dm_error module~dm_hash dm_hash module~dm_hash_table->module~dm_hash module~dm_kind dm_kind module~dm_hash_table->module~dm_kind module~dm_error->module~dm_kind module~dm_ascii dm_ascii module~dm_error->module~dm_ascii module~dm_hash->module~dm_kind module~dm_platform dm_platform module~dm_hash->module~dm_platform iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env

Used by

  • module~~dm_hash_table~~UsedByGraph module~dm_hash_table dm_hash_table module~dm_cgi_router dm_cgi_router module~dm_cgi_router->module~dm_hash_table module~dmpack dmpack module~dmpack->module~dm_hash_table module~dmpack->module~dm_cgi_router

Interfaces

public interface dm_hash_table_get

Generic interface to hash table get functions.

  • private function hash_table_get_index(hash_table, loc, value) result(rc)

    Returns pointer to element in hash table by index loc. On error, value will point to null.

    The function returns the following error codes:

    • E_BOUNDS if the index is outside the array bounds.
    • E_NULL if the hash table value pointer is not associated.

    Arguments

    Type IntentOptional Attributes Name
    type(hash_table_type), intent(inout) :: hash_table

    Hash table type.

    integer, intent(in) :: loc

    Hash value index.

    class(*), intent(out), pointer :: value

    Associated value.

    Return Value integer

  • private function hash_table_get_key(hash_table, key, value) result(rc)

    Returns pointer to element in hash table by key. On error, value will point to null. The intrinsic findloc() should be sufficient for a small number of elements. For larger hash tables, buckets have to be added.

    The function returns the following error codes:

    • E_NOT_FOUND if the key was not found.
    • E_NULL if the hash table value pointer is not associated.

    Arguments

    Type IntentOptional Attributes Name
    type(hash_table_type), intent(inout) :: hash_table

    Hash table type.

    character(len=*), intent(in) :: key

    Hash table key.

    class(*), intent(out), pointer :: value

    Associated value.

    Return Value integer


Derived Types

type, public ::  hash_value_type

Container that keeps generic pointer to hash table value.

Components

Type Visibility Attributes Name Initial
class(*), public, pointer :: ptr => null()

type, public ::  hash_table_type

Opaque hash table type of key-value pairs.


Functions

public function dm_hash_table_create(hash_table, max_entries) result(rc)

Create a new hash table with maximum number of entries.

Arguments

Type IntentOptional Attributes Name
type(hash_table_type), intent(inout) :: hash_table

Hash table type.

integer, intent(in) :: max_entries

Maximum number of entries.

Return Value integer

public function dm_hash_table_is_allocated(hash_table) result(is)

Returns .true. if hash table arrays have been allocated.

Arguments

Type IntentOptional Attributes Name
type(hash_table_type), intent(inout) :: hash_table

Hash table type.

Return Value logical

public function dm_hash_table_set(hash_table, key, value) result(rc)

Adds element to hash table, or replaces existing value. This function does not resolve hash collisions.

Arguments

Type IntentOptional Attributes Name
type(hash_table_type), intent(inout) :: hash_table

Hash table type.

character(len=*), intent(in) :: key

Hash table key.

class(*), intent(inout), target :: value

Associated value.

Return Value integer


Subroutines

public subroutine dm_hash_table_destroy(hash_table)

Finalises hash table. If the hash table items contain allocatable data types, you have to deallocate them manually beforehand.

Arguments

Type IntentOptional Attributes Name
type(hash_table_type), intent(inout) :: hash_table

Hash table type.

public subroutine dm_hash_table_size(hash_table, n, max_size)

Returns cursor position in n and maximum size of hash table in max_size.

Arguments

Type IntentOptional Attributes Name
type(hash_table_type), intent(inout) :: hash_table

Hash table type.

integer, intent(out), optional :: n

Current number of values.

integer, intent(out), optional :: max_size

Max. number of values.