File: example_hashmaps_set_other_data.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 (37 lines) | stat: -rw-r--r-- 1,086 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
program example_set_other_data
  use stdlib_kinds, only: int8
  use stdlib_hashmaps, only: open_hashmap_type, chaining_hashmap_type
  use stdlib_hashmap_wrappers, only: key_type, set
  
  implicit none
  logical :: exists
  type(chaining_hashmap_type) :: map
  class(*), allocatable   :: data
  type(key_type) :: key
    
  ! Initialize hashmap with 2^10 slots.
  ! Hashmap will dynamically increase size if needed.
  call map%init(slots_bits=10)

  call set(key, [5, 7, 4, 13])
  
  call map%map_entry(key, 'A value')
  
  call map%set_other_data(key, 'Another value', exists)
  
  print *, 'The entry to have its other data replaced exists = ', exists
  
  call map%get_other_data(key, data, exists)
  
  print *, 'Get_other_data was successful = ', exists
  
  ! Hashmaps return an unlimited polymorphic type as other.  
  ! Must be included in a select type operation to do further operations.
  select type (data)
  type is (character(*))
    print *, 'Value is = ', data
  class default
    print *, 'Invalid data type in other'
  end select
  
end program example_set_other_data