Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/specs/stdlib_hashmaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,13 @@ The type's definition is below:
end type hashmap_type
```

`hashmap_type` can be used to define a procedure interface that can accept both `open_hashmap_type` and `chaining_hashmap_type`.

##### Example

```fortran
{!example/hashmaps/example_hashmaps_abstract_type.f90!}
```

#### The `chaining_map_entry_type` derived type

Expand Down
1 change: 1 addition & 0 deletions example/hashmaps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ADD_EXAMPLE(hashmaps_abstract_type)
ADD_EXAMPLE(hashmaps_calls)
ADD_EXAMPLE(hashmaps_copy_key)
ADD_EXAMPLE(hashmaps_entries)
Expand Down
51 changes: 51 additions & 0 deletions example/hashmaps/example_hashmaps_abstract_type.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
! For procedure interfaces, consider using abstract hashmap_type for interface definition.
! This allows the procedure to be used for both chaining and open hashmap types.

program example_abstract_type
use stdlib_hashmaps, only: chaining_hashmap_type, open_hashmap_type, hashmap_type

implicit none

integer :: out_value
type(chaining_hashmap_type) :: chaining_map
type(open_hashmap_type) :: open_map

! Chaining map call
call put_int(chaining_map, '1', 1)
call get_int(chaining_map, '1', out_value)
print *, "Chaining out value is ", out_value

! Open map call
call put_int(open_map, '1', 1)
call get_int(open_map, '1', out_value)
print *, "Open out value is ", out_value

contains

subroutine put_int(map, key, value)
class(hashmap_type), intent(inout) :: map
character(len=*), intent(in) :: key
integer, intent(in) :: value

call map%map_entry(key, value)
end subroutine put_int


subroutine get_int(map, key, value)
class(hashmap_type), intent(inout) :: map
character(len=*), intent(in) :: key
integer, intent(out) :: value
class(*), allocatable :: data

call map%get_other_data( key, data)

select type (data)
type is (integer)
value = data
class default
print *, 'Invalid data type in other'
end select
end subroutine get_int


end program example_abstract_type
3 changes: 2 additions & 1 deletion src/stdlib_hashmaps.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module stdlib_hashmaps
!! Public data_types
public :: &
chaining_hashmap_type, &
open_hashmap_type
open_hashmap_type, &
hashmap_type

!! Values that parameterize David Chase's empirical SLOT expansion code
integer, parameter :: &
Expand Down
9 changes: 0 additions & 9 deletions test/hashmaps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
### Pre-process: .fpp -> .f90 via Fypp

# Create a list of the files to be preprocessed
set(fppFiles
test_maps.fypp
)

fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)

ADDTEST(chaining_maps)
ADDTEST(open_maps)
ADDTEST(maps)
Expand Down
Loading
Loading