Octopus
iihash.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2021 S. Ohlmann
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
31
32module iihash_oct_m
33 use debug_oct_m
34 use global_oct_m
35 use iso_c_binding
37
38 implicit none
39
40 private
41 public :: &
42 iihash_t, &
44 iihash_end, &
47 lihash_t, &
49 lihash_end, &
52
53 type iihash_t
54 private
55 type(c_ptr) :: map
56 end type iihash_t
57
58 type lihash_t
59 private
60 type(c_ptr) :: map
61 end type lihash_t
62
63contains
64
65 ! ---------------------------------------------------------
67 subroutine iihash_init(h)
68 type(iihash_t), intent(out) :: h
69
70 interface
71 subroutine iihash_map_init(map)
72 use iso_c_binding
73 implicit none
74
75 type(c_ptr), intent(inout) :: map
76 end subroutine iihash_map_init
77 end interface
78
79
80 push_sub(iihash_init)
81
82 call iihash_map_init(h%map)
83
84 pop_sub(iihash_init)
85 end subroutine iihash_init
86
87
88 ! ---------------------------------------------------------
90 subroutine iihash_end(h)
91 type(iihash_t), intent(inout) :: h
92
93 interface
94 subroutine iihash_map_end(map)
95 use iso_c_binding
96 implicit none
97
98 type(c_ptr), intent(inout) :: map
99 end subroutine iihash_map_end
100 end interface
101
102 push_sub(iihash_end)
103
104 call iihash_map_end(h%map)
105
106 pop_sub(iihash_end)
107 end subroutine iihash_end
108
109
110 ! ---------------------------------------------------------
112 subroutine iihash_insert(h, key, val)
113 type(iihash_t), intent(inout) :: h
114 integer, intent(in) :: key
115 integer, intent(in) :: val
116
117 interface
118 subroutine iihash_map_insert(map, key, val)
119 use iso_c_binding
120 implicit none
121
122 type(c_ptr), intent(inout) :: map
123 integer, intent(in) :: key
124 integer, intent(in) :: val
125 end subroutine iihash_map_insert
126 end interface
127
128 call iihash_map_insert(h%map, key, val)
129 end subroutine iihash_insert
130
131
132 ! ---------------------------------------------------------
137 integer function iihash_lookup(h, key, found)
138 type(iihash_t), intent(in) :: h
139 integer, intent(in) :: key
140 logical, optional, intent(out) :: found
141
142 interface
143 subroutine iihash_map_lookup(map, key, ifound, val)
144 use iso_c_binding
145 implicit none
147 type(c_ptr), intent(in) :: map
148 integer, intent(in) :: key
149 integer, intent(out) :: ifound
150 integer, intent(out) :: val
151 end subroutine iihash_map_lookup
152 end interface
154 integer :: ifound, val
155 logical :: found_
156
157 call iihash_map_lookup(h%map, key, ifound, val)
158
159 found_ = (ifound == 1)
160 if (present(found)) found = found_
161
162 iihash_lookup = -1
163 if (found_) iihash_lookup = val
164
165 end function iihash_lookup
166
167 ! ---------------------------------------------------------
169 subroutine lihash_init(h)
170 type(lihash_t), intent(out) :: h
171
172 interface
173 subroutine lihash_map_init(map)
174 use iso_c_binding
175 implicit none
176
177 type(c_ptr), intent(inout) :: map
178 end subroutine lihash_map_init
179 end interface
180
181
182 push_sub(lihash_init)
184 call lihash_map_init(h%map)
185
186 pop_sub(lihash_init)
187 end subroutine lihash_init
188
189
190 ! ---------------------------------------------------------
192 subroutine lihash_end(h)
193 type(lihash_t), intent(inout) :: h
194
195 interface
196 subroutine lihash_map_end(map)
197 use iso_c_binding
198 implicit none
199
200 type(c_ptr), intent(inout) :: map
201 end subroutine lihash_map_end
202 end interface
203
204 push_sub(lihash_end)
206 call lihash_map_end(h%map)
207
208 pop_sub(lihash_end)
209 end subroutine lihash_end
210
211
212 ! ---------------------------------------------------------
214 subroutine lihash_insert(h, key, val)
215 type(lihash_t), intent(inout) :: h
216 integer(int64), intent(in) :: key
217 integer, intent(in) :: val
218
219 interface
220 subroutine lihash_map_insert(map, key, val)
221 use iso_c_binding
222 use, intrinsic :: iso_fortran_env
223 implicit none
224
225 type(c_ptr), intent(inout) :: map
226 integer(int64), intent(in) :: key
227 integer, intent(in) :: val
228 end subroutine lihash_map_insert
229 end interface
231 call lihash_map_insert(h%map, key, val)
232 end subroutine lihash_insert
233
234
235 ! ---------------------------------------------------------
240 integer function lihash_lookup(h, key, found)
241 type(lihash_t), intent(in) :: h
242 integer(int64), intent(in) :: key
243 logical, optional, intent(out) :: found
244
245 interface
246 subroutine lihash_map_lookup(map, key, ifound, val)
247 use iso_c_binding
248 use, intrinsic :: iso_fortran_env
249 implicit none
250
251 type(c_ptr), intent(in) :: map
252 integer(int64), intent(in) :: key
253 integer, intent(out) :: ifound
254 integer, intent(out) :: val
255 end subroutine lihash_map_lookup
256 end interface
257
258 integer :: ifound, val
259 logical :: found_
260
261 call lihash_map_lookup(h%map, key, ifound, val)
263 found_ = (ifound == 1)
264 if (present(found)) found = found_
265
266 lihash_lookup = -1
267 if (found_) lihash_lookup = val
268
269 end function lihash_lookup
270
271end module iihash_oct_m
272
273!! Local Variables:
274!! mode: f90
275!! coding: utf-8
276!! End:
This module implements a simple hash table for non-negative integer keys and integer values.
Definition: iihash.F90:125
integer function, public lihash_lookup(h, key, found)
Look up a value in the hash table h. If found is present, it indicates if key could be found in the t...
Definition: iihash.F90:334
subroutine, public lihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: iihash.F90:308
subroutine, public iihash_end(h)
Free a hash table.
Definition: iihash.F90:184
subroutine, public lihash_end(h)
Free a hash table.
Definition: iihash.F90:286
subroutine, public lihash_init(h)
Initialize a hash table h.
Definition: iihash.F90:263
subroutine, public iihash_insert(h, key, val)
Insert a (key, val) pair into the hash table h.
Definition: iihash.F90:206
integer function, public iihash_lookup(h, key, found)
Look up a value in the hash table h. If found is present, it indicates if key could be found in the t...
Definition: iihash.F90:231
subroutine, public iihash_init(h)
Initialize a hash table h.
Definition: iihash.F90:161