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) # 255 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" !! 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 # 259 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" CHARACTER(LEN=default_string_length) :: key # 260 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" INTEGER(kind=int_4), intent(in), optional :: default_value # 261 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" INTEGER(kind=int_4) :: value # 262 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" TYPE(private_item_type_str_i4), POINTER :: item # 263 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" 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.") # 273 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" hash = hash_str (key) # 275 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" 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 # 281 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" value =item%value # 282 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" return END IF END IF item => item%next end do IF (PRESENT(default_value)) THEN value =default_value # 290 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" return END IF DBCSR_ABORT("dict_str_i4_get: Key not found in dictionary.") # 294 "/__w/dbcsr/dbcsr/src/core/dbcsr_dict.F" END FUNCTION dict_str_i4_get