Get value for a given key
| Type | Intent | Optional | 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). |
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