Skip to content

Hashmap test update #1025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
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
53 changes: 53 additions & 0 deletions example/hashmaps/example_hashmaps_abstract_type.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

! 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_kinds, only: int8, int64
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