hash_table_get Subroutine

private subroutine hash_table_get(me, key, value, found)

Get value for a given key

Type Bound

json_hash_table

Arguments

Type IntentOptional Attributes Name
class(json_hash_table), intent(in) :: me
character(kind=CK, len=*), intent(in) :: key

key to look up.

type(json_value), pointer :: value

pointer to the value associated with the key. This will be set to null() if the key is not found.

logical(kind=LK), intent(out), optional :: found

flag indicating whether the key was found in the table (true) or not (false).


Calls

proc~~hash_table_get~~CallsGraph proc~hash_table_get json_hash_table%hash_table_get proc~hash_table_hash json_hash_table%hash_table_hash proc~hash_table_get->proc~hash_table_hash proc~keys_equal json_hash_table%keys_equal proc~hash_table_get->proc~keys_equal proc~preprocess_key json_hash_table%preprocess_key proc~hash_table_get->proc~preprocess_key proc~lowercase_string lowercase_string proc~preprocess_key->proc~lowercase_string

Called by

proc~~hash_table_get~~CalledByGraph proc~hash_table_get json_hash_table%hash_table_get proc~json_file_get_object json_file%json_file_get_object proc~json_file_get_object->proc~hash_table_get none~get json_file%get none~get->proc~json_file_get_object proc~json_file_get_alloc_string_vec json_file%json_file_get_alloc_string_vec none~get->proc~json_file_get_alloc_string_vec proc~json_file_get_integer json_file%json_file_get_integer none~get->proc~json_file_get_integer proc~json_file_get_integer_vec json_file%json_file_get_integer_vec none~get->proc~json_file_get_integer_vec proc~json_file_get_logical json_file%json_file_get_logical none~get->proc~json_file_get_logical proc~json_file_get_logical_vec json_file%json_file_get_logical_vec none~get->proc~json_file_get_logical_vec proc~json_file_get_real json_file%json_file_get_real none~get->proc~json_file_get_real proc~json_file_get_real32 json_file%json_file_get_real32 none~get->proc~json_file_get_real32 proc~json_file_get_real32_vec json_file%json_file_get_real32_vec none~get->proc~json_file_get_real32_vec proc~json_file_get_real_vec json_file%json_file_get_real_vec none~get->proc~json_file_get_real_vec proc~json_file_get_string json_file%json_file_get_string none~get->proc~json_file_get_string proc~json_file_get_string_vec json_file%json_file_get_string_vec none~get->proc~json_file_get_string_vec proc~wrap_json_file_get_alloc_string_vec json_file%wrap_json_file_get_alloc_string_vec none~get->proc~wrap_json_file_get_alloc_string_vec proc~wrap_json_file_get_integer json_file%wrap_json_file_get_integer none~get->proc~wrap_json_file_get_integer proc~wrap_json_file_get_integer_vec json_file%wrap_json_file_get_integer_vec none~get->proc~wrap_json_file_get_integer_vec proc~wrap_json_file_get_logical json_file%wrap_json_file_get_logical none~get->proc~wrap_json_file_get_logical proc~wrap_json_file_get_logical_vec json_file%wrap_json_file_get_logical_vec none~get->proc~wrap_json_file_get_logical_vec proc~wrap_json_file_get_object json_file%wrap_json_file_get_object none~get->proc~wrap_json_file_get_object proc~wrap_json_file_get_real json_file%wrap_json_file_get_real none~get->proc~wrap_json_file_get_real proc~wrap_json_file_get_real32 json_file%wrap_json_file_get_real32 none~get->proc~wrap_json_file_get_real32 proc~wrap_json_file_get_real32_vec json_file%wrap_json_file_get_real32_vec none~get->proc~wrap_json_file_get_real32_vec proc~wrap_json_file_get_real_vec json_file%wrap_json_file_get_real_vec none~get->proc~wrap_json_file_get_real_vec proc~wrap_json_file_get_string json_file%wrap_json_file_get_string none~get->proc~wrap_json_file_get_string proc~wrap_json_file_get_string_vec json_file%wrap_json_file_get_string_vec none~get->proc~wrap_json_file_get_string_vec proc~initialize_hash json_file%initialize_hash proc~initialize_hash->none~get proc~json_file_get_alloc_string_vec->none~get proc~json_file_get_integer->none~get proc~json_file_get_integer_vec->none~get proc~json_file_get_logical->none~get proc~json_file_get_logical_vec->none~get proc~json_file_get_real->none~get proc~json_file_get_real32->none~get proc~json_file_get_real32_vec->none~get proc~json_file_get_real_vec->none~get proc~json_file_get_string->none~get proc~json_file_get_string_vec->none~get proc~wrap_json_file_get_alloc_string_vec->none~get proc~wrap_json_file_get_integer->none~get proc~wrap_json_file_get_integer_vec->none~get proc~wrap_json_file_get_logical->none~get proc~wrap_json_file_get_logical_vec->none~get proc~wrap_json_file_get_object->none~get proc~wrap_json_file_get_real->none~get proc~wrap_json_file_get_real32->none~get proc~wrap_json_file_get_real32_vec->none~get proc~wrap_json_file_get_real_vec->none~get proc~wrap_json_file_get_string->none~get proc~wrap_json_file_get_string_vec->none~get

Source Code

    subroutine hash_table_get(me, key, value, found)

    class(json_hash_table), intent(in) :: me
    character(kind=CK,len=*), intent(in) :: key !! key to look up.
    type(json_value), pointer :: value !! pointer to the value associated with the key.
                                       !! This will be set to null() if the key is not found.
    logical(LK), intent(out), optional :: found !! flag indicating whether the key was found in
                                                !! the table (true) or not (false).

    integer(IK) :: bucket_idx !! index of the bucket for this key
    type(hash_node_t), pointer :: current !! pointer for traversing the linked list in the bucket
    character(kind=CK,len=:), allocatable :: key_to_search !! the key after preprocessing (trimming and/or lowercasing)

    value => null()
    if (present(found)) found = .false.

    if (.not. allocated(me%buckets)) return

    key_to_search = me%preprocess_key(key)

    bucket_idx = me%hash(key_to_search)
    current => me%buckets(bucket_idx)%next

    do while (associated(current))
        if (me%keys_equal(current%key, key_to_search)) then
            value => current%value
            if (present(found)) found = .true.
            return
        end if
        current => current%next
    end do

    end subroutine hash_table_get