-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabstract_map_class.f90
101 lines (44 loc) · 1.58 KB
/
abstract_map_class.f90
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
module abstract_map_class
use map_interface, only : map
use object_class, only : object
implicit none
private
public :: abstract_map, map_entry
type, abstract, extends(map) :: abstract_map
contains
procedure :: is_empty
end type abstract_map
type, extends(object) :: map_entry
class(*) , allocatable :: key
class(*) , allocatable :: value
type(map_entry) , pointer :: next
contains
! Override equals and hashcode of object type
! procedure :: equals => equals
! procedure :: hashcode => hashcode
! procedure :: get_key
! procedure :: get_value, set_value
! procedure :: to_string
end type map_entry
! Contructor interface
interface map_entry
module procedure create_map_entry
end interface map_entry
contains
type(map_entry) function create_map_entry(hash, key, value, next) &
& result(this)
type(integer) , intent(in) :: hash
class(*) , intent(in) :: key
class(*) , intent(in) :: value
type(map_entry) , pointer :: next
allocate(this % key, source = key)
allocate(this % value, source = value)
end function create_map_entry
!===================================================================!
! Returns .true. if the map is empty
!===================================================================!
type(logical) function is_empty(this)
class(abstract_map) :: this
is_empty = this % size() .eq. 0
end function is_empty
end module abstract_map_class