LKedward / fhash

fpm package implementing a hash table with support for generic keys and values.
https://lkedward.github.io/fhash/
MIT License
38 stars 8 forks source link

Do not report error if the key are not in dictionary #20

Closed jiangleads closed 2 months ago

jiangleads commented 2 months ago

Hello, I had build this cod under Intel Compile. Everything is ok except it do not report error when the keys are not in the dictionary. Can it report error when the keys are not in dictionary? the codes are below:

program test
    use fhash, only: fhash_tbl_t, key=>fhash_key
    implicit none
    integer :: istation
    type(fhash_tbl_t) :: tbl
    call tbl%set(key("key1"), value=1)
    call tbl%get(key("key1"),istation)
    print*,'key1',istation

    call tbl%set(key("key2"), value=2)
    call tbl%get(key("key2"),istation)
    print*,'key2',istation

    call tbl%set(key("key3"), value=3)
    call tbl%get(key("key3"),istation)
    print*,'key3',istation

    call tbl%get(key("NONE"),istation)
    print*,'NONE',istation

end program
LKedward commented 2 months ago

Hi, yes this is possible using the optional status variable:


program test
  use fhash, only: fhash_tbl_t, key=>fhash_key
  implicit none
  integer :: istation, status
  type(fhash_tbl_t) :: tbl

  call tbl%get(key("NONE"),istation,stat=status)
  if (status /= 0) then
    Print*, "Key not found"
  else
    print*,istation
  end if

end program
jiangleads commented 2 months ago

Hi, yes this is possible using the optional status variable:

program test
  use fhash, only: fhash_tbl_t, key=>fhash_key
  implicit none
  integer :: istation, status
  type(fhash_tbl_t) :: tbl

  call tbl%get(key("NONE"),istation,stat=status)
  if (status /= 0) then
    Print*, "Key not found"
  else
    print*,istation
  end if

end program

Hello, Thank you for your reply! That is great! Awsome :)