dc_hash Module Reference

Data Types

interface  dchashdelete
 
interface  dchashget
 
interface  dchashnext
 
interface  dchashnumber
 
interface  dchashput
 
interface  dchashputline
 
interface  dchashrewind
 
interface  delete
 
interface  get
 
type  hash
 
type  hash_internal
 
interface  next
 
interface  number
 
interface  put
 
interface  putline
 
interface  rewind
 

Functions/Subroutines

subroutine dchashput0 (hashv, key, value)
 
integer function dchashnumber0 (hashv)
 
subroutine dchashrewind0 (hashv)
 
subroutine dchashnext0 (hashv, key, value, end)
 
subroutine dchashputline0 (hashv)
 
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 
種別型パラメタを提供します。
Definition: dc_types.f90:49
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118

◆ dchashnext0()

subroutine dc_hash::dchashnext0 ( type(hash), intent(inout)  hashv,
character(*), intent(out)  key,
character(*), intent(out), optional  value,
logical, intent(out)  end 
)
private

Definition at line 267 of file dc_hash.f90.

267  !
268 
269  ! *hashv* の内容を *key* と *value* に返します.
270  ! 詳しくは DCHashRewind を参照してください.
271  !
272  implicit none
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
279  continue
280  table_size = dchashnumber(hashv)
281  if (table_size < hashv % search_index) then
282  key = ''
283  value_tmp = ''
284  end = .true.
285  else
286  key = hashv % hash_table(hashv % search_index) % key
287  value_tmp = hashv % hash_table(hashv % search_index) % value
288  end = .false.
289  hashv % search_index = hashv % search_index + 1
290  end if
291  if (present(value)) then
292  value = value_tmp
293  end if
294 

◆ dchashnumber0()

integer function dc_hash::dchashnumber0 ( type(hash), intent(in)  hashv)
private

Definition at line 222 of file dc_hash.f90.

222  !
223  ! *hashv* のサイズを返します.
224  !
225  implicit none
226  type(hash), intent(in) :: hashv
227  integer :: result
228  continue
229  if (associated(hashv % hash_table)) then
230  result = size(hashv % hash_table)
231  else
232  result = 0
233  end if

◆ dchashput0()

subroutine dc_hash::dchashput0 ( type(hash), intent(inout)  hashv,
character(*), intent(in)  key,
character(*), intent(in)  value 
)
private

Definition at line 181 of file dc_hash.f90.

181  !
182  ! *hashv* のキー *key* に値 *value* を関連付けます.
183  !
184  implicit none
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
189  logical :: found
190  character(STRING) :: search_value
191  continue
192  call dchashget(hashv, key, search_value, found)
193  if (.not. found) then
194  table_size = dchashnumber(hashv)
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
203  else
204  allocate(hashv % hash_table(1))
205  new_index = 1
206  end if
207 
208  hashv % hash_table(new_index) % key = key
209  hashv % hash_table(new_index) % value = value
210  else
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
214  end if
215  end do
216  end if
217 

◆ dchashputline0()

subroutine dc_hash::dchashputline0 ( type(hash), intent(in)  hashv)
private

Definition at line 299 of file dc_hash.f90.

References dc_string::joinchar(), and dc_types::string.

299  !
300  ! *hashv* の内容を標準出力に表示します.
301  !
302  use dc_types, only: string
303  use dc_string, only: printf, joinchar
304  implicit none
305  type(hash), intent(in) :: hashv
306  type(hash) :: hashv_tmp
307  character(len = STRING):: key, value
308  logical:: end
309  continue
310  hashv_tmp = hashv
311 
312  call printf(6, '#<HASH:: ')
313  call dchashrewind(hashv_tmp)
314  do
315  call dchashnext(hashv_tmp, key, value, end)
316  if (end) exit
317  call printf(6, ' "%c" -> "%c",', &
318  & c1=trim(key), c2=trim(value))
319  enddo
320  call printf(6, '> ')
321 
character(string) function, public joinchar(carray, expr)
Definition: dc_string.f90:861
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118
Here is the call graph for this function:

◆ dchashrewind0()

subroutine dc_hash::dchashrewind0 ( type(hash), intent(inout)  hashv)
private

Definition at line 237 of file dc_hash.f90.

237  !
238  ! 主にハッシュの内容を取り出すことを目的として,
239  ! *hashv* の巻き戻しを行います. DCHashNext との組み合わせによって
240  ! キーと値のリストを取得すること可能です.
241  !
242  ! 以下のサンプルソースコードを参照ください.
243  !
244  ! program hash_sample
245  ! use dc_type
246  ! use dc_hash
247  ! type(HASH):: hashv
248  ! character(len = STRING):: key, value
249  ! logical:: end
250  !
251  ! call DCHashRewind( hashv ) ! (inout)
252  ! do
253  ! call DCHashNext( hashv = hashv, & ! (inout)
254  ! & key = key, value = value, end = end) ! (out)
255  ! if (end) exit
256  ! write(*,*) 'key=' // trim(key) // ', value=' // trim(value)
257  ! enddo
258  ! end program hash_sample
259  !
260  implicit none
261  type(hash), intent(inout) :: hashv
262  continue
263  hashv % search_index = 1