46 class(*),
pointer :: value
54 procedure :: sphash_value_constructor
61 type(c_ptr) :: map = c_null_ptr
71 type(c_ptr) :: iterator = c_null_ptr
72 type(c_ptr) :: end = c_null_ptr
84 class(*),
target,
intent(in) :: value
85 logical,
optional,
intent(in) :: clone
86 type(sphash_value_t),
pointer :: constructor
91 if (constructor%clone)
then
92 allocate(constructor%value, source=
value)
94 constructor%value =>
value
102 type(sphash_value_t) :: this
104 if (
associated(this%value))
then
106 deallocate(this%value)
116 class(sphash_value_t),
intent(in) :: this
117 class(*),
pointer :: value
128 type(sphash_t),
intent(out) :: h
131 subroutine sphash_map_init(map)
bind(c)
137 end subroutine sphash_map_init
140 call sphash_map_init(h%map)
157 type(c_ptr) :: tmp_ptr
161 subroutine sphash_iterator_low_get(iterator, value_ptr)
bind(c)
166 type(c_ptr),
intent(in) :: iterator
167 type(c_ptr),
intent(out) :: value_ptr
169 end subroutine sphash_iterator_low_get
171 subroutine sphash_map_end(map)
bind(c)
177 end subroutine sphash_map_end
182 do while (it%has_next())
183 call sphash_iterator_low_get(it%iterator, tmp_ptr)
184 call c_f_pointer(tmp_ptr, tmp_value)
185 deallocate(tmp_value)
188 call sphash_map_end(h%map)
199 character(len=*),
intent(in) :: key
200 class(*),
target,
intent(in) :: val
201 logical,
optional,
intent(in) :: clone
206 subroutine sphash_map_insert(map, key, val)
bind(c)
211 type(c_ptr),
value :: map
212 character(kind=c_char),
intent(in) :: key(*)
213 type(c_ptr),
value :: val
214 end subroutine sphash_map_insert
219 call sphash_map_insert(h%map,
string_f_to_c(key), c_loc(
value))
231 character(len=*),
intent(in) :: key
232 logical,
optional,
intent(out) :: found
233 class(*),
pointer :: value
237 character(kind=c_char),
dimension(c_str_len(key)) :: c_key
240 subroutine sphash_map_lookup(map, key, ifound, val)
bind(c)
244 type(c_ptr),
value :: map
245 character(kind=c_char),
intent(in) :: key(*)
246 integer(kind=c_int),
intent(out) :: ifound
247 type(c_ptr),
intent(out) :: val
248 end subroutine sphash_map_lookup
256 call sphash_map_lookup(h%map, c_key, ifound, val)
258 found_ = (ifound == 1)
259 if (
present(found)) found = found_
263 call c_f_pointer(val, tmp_value)
264 value => tmp_value%get()
275 subroutine sphash_iterator_low_start(iterator, end, map)
bind(c)
280 type(c_ptr) :: iterator
282 type(c_ptr),
value :: map
283 end subroutine sphash_iterator_low_start
286 call sphash_iterator_low_start(this%iterator, this%end, h%map)
297 subroutine sphash_iterator_low_has_next(iterator, end, value)
bind(c)
302 type(c_ptr),
value,
intent(in) :: iterator
303 type(c_ptr),
value,
intent(in) :: end
304 integer(kind=c_int),
intent(out) :: value
306 end subroutine sphash_iterator_low_has_next
309 call sphash_iterator_low_has_next(this%iterator, this%end,
value)
318 class(*),
pointer :: value
320 type(c_ptr) :: tmp_ptr
324 subroutine sphash_iterator_low_get(iterator, value_ptr)
bind(c)
329 type(c_ptr),
intent(in) :: iterator
330 type(c_ptr),
intent(out) :: value_ptr
332 end subroutine sphash_iterator_low_get
335 call sphash_iterator_low_get(this%iterator, tmp_ptr)
337 call c_f_pointer(tmp_ptr, tmp_value)
338 value => tmp_value%get()
This module implements a simple hash table for string valued keys and integer values using the C++ ST...
class(*) function, pointer sphash_iterator_get_next(this)
subroutine sphash_value_finalize(this)
subroutine, public sphash_init(h)
Initialize a hash table h with size entries. Since we use separate chaining, the number of entries in...
subroutine, public sphash_insert(h, key, val, clone)
Insert a (key, val) pair into the hash table h. If clone=.true., the object will be copied.
logical function sphash_iterator_has_next(this)
class(*) function, pointer sphash_value_get(this)
subroutine, public sphash_end(h)
Free a hash table.
type(sphash_value_t) function, pointer sphash_value_constructor(value, clone)
class(*) function, pointer, public sphash_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...
subroutine sphash_iterator_start(this, h)
logical function sphash_is_associated(this)
Check if the sphash attribute, map, is associated.
character(kind=c_char, len=1) function, dimension(c_str_len(f_string)), public string_f_to_c(f_string)
convert a Fortran string to a C string