File: example_hashmaps_get_all_keys.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (38 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
program example_hashmaps_get_all_keys
  use stdlib_kinds, only: int32
  use stdlib_hashmaps, only: chaining_hashmap_type
  use stdlib_hashmap_wrappers, only: get, key_type, set
  implicit none
  type(chaining_hashmap_type) :: map
  type(key_type)   :: key

  type(key_type), allocatable :: keys(:)
  integer(int32) :: i
  
  character(:), allocatable :: str

  ! adding key-value pairs to the map
  call set(key, "initial key")
  call map%map_entry(key, "value 1")

  call set(key, "second key")
  call map%map_entry(key, "value 2")

  call set(key, "last key")
  call map%map_entry(key, "value 3")

  ! getting all the keys in the map
  call map%get_all_keys(keys)

  print '("Number of keys in the hashmap = ", I0)', size(keys)
  !Number of keys in the hashmap = 3

  do i = 1, size(keys)
    call get( keys(i), str )  
    print '("Value of key ", I0, " = ", A)', i, str
  end do
  !Value of key 1 = initial key
  !Value of key 2 = second key
  !Value of key 3 = last key

end program example_hashmaps_get_all_keys