Insert key with value, or overwrite the value of an existing key.
A key that is not present is appended at the end of the iteration order. A key that is already present keeps its position in the iteration order and only its value changes.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | key |
Stored verbatim; trailing blanks are part of the key. |
||
| integer(kind=int64), | intent(in) | :: | value |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | entry | ||||
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=default_int), | private | :: | klen |
subroutine hash_map_insert(this, key, value) !! Insert `key` with `value`, or overwrite the value of an existing key. !! !! A key that is not present is appended at the end of the iteration !! order. A key that is already present keeps its position in the !! iteration order and only its value changes. class(hash_map_t), intent(inout) :: this character(len=*), intent(in) :: key !! Stored verbatim; trailing blanks are part of the key. integer(int64), intent(in) :: value integer(default_int) :: entry, klen, i if (this%n_buckets == 0) call this%init() entry = find_entry(this, key) if (entry > 0) then this%entry_value(entry) = value return end if if ((this%n_entries + 1)*LOAD_DEN > this%n_buckets*LOAD_NUM) then call grow_buckets(this) end if klen = int(len(key), default_int) call reserve_entries(this, this%n_entries + 1) call reserve_pool(this, this%pool_used + klen) this%n_entries = this%n_entries + 1 this%key_start(this%n_entries) = this%pool_used + 1 this%key_size(this%n_entries) = klen this%entry_value(this%n_entries) = value do i = 1, klen this%key_pool(this%pool_used + i) = key(i:i) end do this%pool_used = this%pool_used + klen this%buckets(probe_free(this, key)) = this%n_entries end subroutine hash_map_insert