276 subroutine dchashput0(hashv, key, value)
278 type(
hash),
intent(inout) :: hashv
279 character(*),
intent(in) :: key, value
280 type(hash_internal),
pointer :: hash_table_tmp(:) => null()
281 integer :: table_size, new_index, i
283 character(STRING) :: search_value
285 call dchashget(hashv, key, search_value, found)
286 if (.not. found)
then
288 if (table_size > 0)
then
289 allocate(hash_table_tmp(table_size))
290 hash_table_tmp = hashv % hash_table
291 deallocate(hashv % hash_table)
292 allocate(hashv % hash_table(table_size + 1))
293 hashv % hash_table(1:table_size) = hash_table_tmp(1:table_size)
294 deallocate(hash_table_tmp)
295 new_index = table_size + 1
297 allocate(hashv % hash_table(1))
301 hashv % hash_table(new_index) % key = key
302 hashv % hash_table(new_index) % value =
value
304 do i = 1,
size(hashv % hash_table)
305 if (trim(hashv % hash_table(i) % key) == trim(key))
then
306 hashv % hash_table(i) % value =
value
431 subroutine dchashnext0(hashv, key, value, end)
433 type(
hash),
intent(inout) :: hashv
434 character(*),
intent(out) :: key
435 character(*),
intent(out),
optional :: value
436 logical,
intent(out) :: end
437 integer :: table_size
438 character(STRING) :: value_tmp
441 if (table_size < hashv % search_index)
then
446 key = hashv % hash_table(hashv % search_index) % key
447 value_tmp = hashv % hash_table(hashv % search_index) % value
449 hashv % search_index = hashv % search_index + 1
451 if (
present(
value))
then
530 subroutine dchashget0(hashv, key, value, found)
533 type(
hash),
intent(inout) :: hashv
534 character(*),
intent(in) :: key
535 character(*),
intent(out) :: value
536 logical,
intent(out),
optional :: found
537 character(STRING) :: search_key, search_value
542 call dchashnext(hashv, search_key, search_value,
end)
545 if (
present(found)) found = .false.
549 if (trim(search_key) == trim(key))
then
551 if (
present(found)) found = .true.
582 subroutine dchashdelete0(hashv, key)
584 type(
hash),
intent(inout) :: hashv
585 character(*),
intent(in),
optional :: key
586 type(hash_internal),
pointer :: hash_table_tmp(:) => null()
587 integer :: table_size, i, j
589 character(STRING) :: search_value
591 if (
present(key))
then
592 call dchashget(hashv, key, search_value, found)
594 if (found .and. table_size > 1)
then
595 allocate(hash_table_tmp(table_size))
596 hash_table_tmp = hashv % hash_table
597 deallocate(hashv % hash_table)
598 allocate(hashv % hash_table(table_size - 1))
601 if (trim(hash_table_tmp(i) % key) /= trim(key))
then
602 hashv % hash_table(j) % key = hash_table_tmp(i) % key
603 hashv % hash_table(j) % value = hash_table_tmp(i) % value
608 deallocate(hash_table_tmp)
609 elseif (found .and. table_size == 1)
then
610 deallocate(hashv % hash_table)
613 if (
associated(hashv % hash_table))
deallocate(hashv % hash_table)