Gets a value for a given key from the dictionary. If the key is not found the default_value will be returned. If the key is not found and default_value was not provided the program stops.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dict_str_i4_type), | intent(inout) | :: | dict | |||
character(len=default_string_length) | :: | key | ||||
integer(kind=int_4), | intent(in), | optional | :: | default_value |
FUNCTION dict_str_i4_get(dict, key, default_value) RESULT(value) !! Gets a value for a given key from the dictionary. !! If the key is not found the default_value will be returned. !! If the key is not found and default_value was not provided the program stops. TYPE(dict_str_i4_type), intent(inout) :: dict CHARACTER(LEN=default_string_length) :: key INTEGER(kind=int_4), intent(in), optional :: default_value INTEGER(kind=int_4) :: value TYPE(private_item_type_str_i4), POINTER :: item INTEGER(KIND=int_8) :: hash, idx # 266 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" value = 0 # 270 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" IF (.not. ASSOCIATED(dict%buckets)) & DBCSR_ABORT("dict_str_i4_get: dictionary is not initialized.") hash = hash_str (key) idx = MOD(hash, INT(size(dict%buckets), KIND=int_8)) + 1 item => dict%buckets(idx)%p do while (ASSOCIATED(item)) IF (item%hash == hash) THEN IF (item%key == key) THEN value =item%value return END IF END IF item => item%next end do IF (PRESENT(default_value)) THEN value =default_value return END IF DBCSR_ABORT("dict_str_i4_get: Key not found in dictionary.") END FUNCTION dict_str_i4_get