Data Types | Functions/Subroutines
dc_hash Module Reference

Functions/Subroutines

subroutine dchashget0 (hashv, key, value, found)
 
subroutine dchashdelete0 (hashv, key)
 

Function/Subroutine Documentation

◆ dchashdelete0()

subroutine dc_hash::dchashdelete0 ( type(hash), intent(inout)  hashv,
character(*), intent(in), optional  key 
)

Definition at line 362 of file dc_hash.f90.

362  !
363  ! *hashv* のキー *key* およびその関連する値を削除します.
364  ! *hashv* 内に *key* が見つからない場合には何もしません.
365  !
366  ! *key* が省略される場合には *hashv* 内の全てのキーと値を
367  ! 削除します.
368  !
369  implicit none
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
374  logical :: found
375  character(STRING) :: search_value
376  continue
377  if (present(key)) then
378  call dchashget(hashv, key, search_value, found)
379  table_size = dchashnumber(hashv)
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))
385  j = 1
386  do i = 1, table_size
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
390  j = j + 1
391  end if
392  end do
393 
394  deallocate(hash_table_tmp)
395  elseif (found .and. table_size == 1) then
396  deallocate(hashv % hash_table)
397  end if
398  else
399  if (associated(hashv % hash_table)) deallocate(hashv % hash_table)
400  end if
401 

◆ dchashget0()

subroutine dc_hash::dchashget0 ( type(hash), intent(inout)  hashv,
character(*), intent(in)  key,
character(*), intent(out)  value,
logical, intent(out), optional  found 
)

Definition at line 326 of file dc_hash.f90.

References dc_types::string.

326  !
327  ! *hashv* のキー *key* に関連する値を *value* に返します.
328  ! *key* に関連する値が存在しない場合は *value* に
329  ! 空文字を返します.
330  !
331  ! *found* を与えると, *key* に関連する値が見つからなかった
332  ! 場合に .false. を返します.
333  !
334  use dc_types, only: string
335  implicit none
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
341  logical :: end
342  continue
343  call dchashrewind(hashv)
344  do
345  call dchashnext(hashv, search_key, search_value, end)
346  if (end) then
347  value = ''
348  if (present(found)) found = .false.
349  exit
350  end if
351 
352  if (trim(search_key) == trim(key)) then
353  value = search_value
354  if (present(found)) found = .true.
355  exit
356  end if
357  enddo
358 
Provides kind type parameter values.
Definition: dc_types.f90:49
integer, parameter, public string
Character length for string.
Definition: dc_types.f90:118