Skip to content

Commit 6937b24

Browse files
committed
added implementation of get_all_open_keys
1 parent 4ce674e commit 6937b24

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/stdlib_hashmap_open.f90

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,37 @@ module subroutine free_open_map( map )
254254
end subroutine free_open_map
255255

256256

257+
module subroutine get_all_open_keys(map, all_keys)
258+
!! Version: Experimental
259+
!!
260+
!! Returns all the keys presented in a hash map
261+
!! Arguments:
262+
!! map - an open hash map
263+
!! all_keys - all the keys presented in a hash map
264+
!
265+
class(open_hashmap_type), intent(in) :: map
266+
type(key_type), allocatable, intent(out) :: all_keys(:)
267+
268+
integer(int32) :: num_keys
269+
integer(int_index) :: i, key_idx
270+
271+
num_keys = map % entries()
272+
allocate( all_keys(num_keys) )
273+
if ( num_keys == 0 ) return
274+
275+
if ( allocated( map % inverse) ) then
276+
key_idx = 1_int_index
277+
do i=1_int_index, size( map % inverse, kind=int_index )
278+
if ( associated( map % inverse(i) % target ) ) then
279+
all_keys(key_idx) = map % inverse(i) % target % key
280+
key_idx = key_idx + 1_int_index
281+
end if
282+
end do
283+
end if
284+
285+
end subroutine get_all_open_keys
286+
287+
257288
module subroutine get_other_open_data( map, key, other, exists )
258289
!! Version: Experimental
259290
!!

0 commit comments

Comments
 (0)