180 subroutine dchashput0(hashv, key, value)
185 type(
hash),
intent(inout) :: hashv
186 character(*),
intent(in) :: key, value
187 type(hash_internal),
pointer :: hash_table_tmp(:) => null()
188 integer :: table_size, new_index, i
190 character(STRING) :: search_value
192 call dchashget(hashv, key, search_value, found)
193 if (.not. found)
then
195 if (table_size > 0)
then
196 allocate(hash_table_tmp(table_size))
197 hash_table_tmp = hashv % hash_table
198 deallocate(hashv % hash_table)
199 allocate(hashv % hash_table(table_size + 1))
200 hashv % hash_table(1:table_size) = hash_table_tmp(1:table_size)
201 deallocate(hash_table_tmp)
202 new_index = table_size + 1
204 allocate(hashv % hash_table(1))
208 hashv % hash_table(new_index) % key = key
209 hashv % hash_table(new_index) % value =
value
211 do i = 1,
size(hashv % hash_table)
212 if (trim(hashv % hash_table(i) % key) == trim(key))
then
213 hashv % hash_table(i) % value =
value
266 subroutine dchashnext0(hashv, key, value, end)
273 type(
hash),
intent(inout) :: hashv
274 character(*),
intent(out) :: key
275 character(*),
intent(out),
optional :: value
276 logical,
intent(out) :: end
277 integer :: table_size
278 character(STRING) :: value_tmp
281 if (table_size < hashv % search_index)
then
286 key = hashv % hash_table(hashv % search_index) % key
287 value_tmp = hashv % hash_table(hashv % search_index) % value
289 hashv % search_index = hashv % search_index + 1
291 if (
present(
value))
then
325 subroutine dchashget0(hashv, key, value, found)
336 type(
hash),
intent(inout) :: hashv
337 character(*),
intent(in) :: key
338 character(*),
intent(out) :: value
339 logical,
intent(out),
optional :: found
340 character(STRING) :: search_key, search_value
345 call dchashnext(hashv, search_key, search_value,
end)
348 if (
present(found)) found = .false.
352 if (trim(search_key) == trim(key))
then
354 if (
present(found)) found = .true.
361 subroutine dchashdelete0(hashv, key)
370 type(
hash),
intent(inout) :: hashv
371 character(*),
intent(in),
optional :: key
372 type(hash_internal),
pointer :: hash_table_tmp(:) => null()
373 integer :: table_size, i, j
375 character(STRING) :: search_value
377 if (
present(key))
then
378 call dchashget(hashv, key, search_value, found)
380 if (found .and. table_size > 1)
then
381 allocate(hash_table_tmp(table_size))
382 hash_table_tmp = hashv % hash_table
383 deallocate(hashv % hash_table)
384 allocate(hashv % hash_table(table_size - 1))
387 if (trim(hash_table_tmp(i) % key) /= trim(key))
then
388 hashv % hash_table(j) % key = hash_table_tmp(i) % key
389 hashv % hash_table(j) % value = hash_table_tmp(i) % value
394 deallocate(hash_table_tmp)
395 elseif (found .and. table_size == 1)
then
396 deallocate(hashv % hash_table)
399 if (
associated(hashv % hash_table))
deallocate(hashv % hash_table)