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
85 class(*),
target :: value
86 logical,
optional :: clone
87 type(sphash_value_t),
pointer :: constructor
92 if (constructor%clone)
then
93 allocate(constructor%value, source=
value)
95 constructor%value =>
value
103 type(sphash_value_t) :: this
105 if (
associated(this%value))
then
107 deallocate(this%value)
117 class(sphash_value_t),
intent(in) :: this
118 class(*),
pointer :: value
129 type(sphash_t),
intent(out) :: h
132 subroutine sphash_map_init(map)
bind(c)
138 end subroutine sphash_map_init
141 call sphash_map_init(h%map)
158 type(c_ptr) :: tmp_ptr
162 subroutine sphash_iterator_low_get(iterator, value_ptr)
bind(c)
167 type(c_ptr),
intent(in) :: iterator
168 type(c_ptr),
intent(out) :: value_ptr
170 end subroutine sphash_iterator_low_get
172 subroutine sphash_map_end(map)
bind(c)
178 end subroutine sphash_map_end
183 do while (it%has_next())
184 call sphash_iterator_low_get(it%iterator, tmp_ptr)
185 call c_f_pointer(tmp_ptr, tmp_value)
186 deallocate(tmp_value)
189 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
236 character(kind=c_char),
dimension(c_str_len(key)) :: c_key
239 subroutine sphash_map_lookup(map, key, ifound, val)
bind(c)
243 type(c_ptr),
value :: map
244 character(kind=c_char),
intent(in) :: key(*)
245 integer(kind=c_int),
intent(out) :: ifound
246 type(c_ptr),
intent(out) :: val
247 end subroutine sphash_map_lookup
255 call sphash_map_lookup(h%map, c_key, ifound, val)
257 found = (ifound == 1)
261 call c_f_pointer(val, tmp_value)
262 value => tmp_value%get()
273 subroutine sphash_iterator_low_start(iterator, end, map)
bind(c)
278 type(c_ptr) :: iterator
280 type(c_ptr),
value :: map
281 end subroutine sphash_iterator_low_start
284 call sphash_iterator_low_start(this%iterator, this%end, h%map)
295 subroutine sphash_iterator_low_has_next(iterator, end, value)
bind(c)
300 type(c_ptr),
value,
intent(in) :: iterator
301 type(c_ptr),
value,
intent(in) :: end
302 integer(kind=c_int),
intent(out) :: value
304 end subroutine sphash_iterator_low_has_next
307 call sphash_iterator_low_has_next(this%iterator, this%end,
value)
316 class(*),
pointer :: value
318 type(c_ptr) :: tmp_ptr
322 subroutine sphash_iterator_low_get(iterator, value_ptr)
bind(c)
327 type(c_ptr),
intent(in) :: iterator
328 type(c_ptr),
intent(out) :: value_ptr
330 end subroutine sphash_iterator_low_get
333 call sphash_iterator_low_get(this%iterator, tmp_ptr)
335 call c_f_pointer(tmp_ptr, tmp_value)
336 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)