Skip to content
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

Remove other derived type from hashmap #843

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
51a55df
RC1
chuckyvt Jun 30, 2024
1888280
Update src/stdlib_hashmap_chaining.f90
chuckyvt Jul 3, 2024
fa23a44
Update src/stdlib_hashmap_open.f90
chuckyvt Jul 3, 2024
18ed909
Update src/stdlib_hashmap_chaining.f90
chuckyvt Jul 3, 2024
97ae06d
Other_type cleanup and removal
chuckyvt Jul 3, 2024
cd435fc
Merge branch 'remove_other_type' of https://github.com/chuckyvt/stdli…
chuckyvt Jul 3, 2024
1906b4c
Remove other type from test_chaining and test_open
chuckyvt Jul 3, 2024
a52302d
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 3, 2024
a31b2f9
Update example_hashmaps_set_other_data.f90
chuckyvt Jul 3, 2024
f47b4c5
Update CMakeLists.txt
chuckyvt Jul 4, 2024
ed99423
Update CMakeLists.txt
chuckyvt Jul 4, 2024
3d1adc8
Update CMakeLists.txt
chuckyvt Jul 4, 2024
50ae961
Revert "Update CMakeLists.txt"
chuckyvt Jul 4, 2024
d5f098e
Update CMakeLists.txt
chuckyvt Jul 4, 2024
b10a851
Update example_hashmaps_set_other_data.f90
chuckyvt Jul 4, 2024
cba213d
Update stdlib_hashmaps.md
chuckyvt Jul 7, 2024
16d2d34
Update to remove other_type references
chuckyvt Jul 10, 2024
8ade03d
Update example_hashmaps_map_entry.f90
chuckyvt Jul 10, 2024
793c049
Update example_hashmaps_rehash.f90
chuckyvt Jul 10, 2024
25a1146
Update example_hashmaps_remove.f90
chuckyvt Jul 10, 2024
775be76
Test allocate again
chuckyvt Jul 10, 2024
154579e
Update to include allocate statement
chuckyvt Jul 10, 2024
d32406b
Typo fix
chuckyvt Jul 10, 2024
b73e0fc
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
244b308
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
6c73db7
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
054f712
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
057fcac
Update example/hashmaps/CMakeLists.txt
chuckyvt Jul 11, 2024
c3e4d31
Update example/hashmaps/example_hashmaps_get_other_data.f90
chuckyvt Jul 11, 2024
facd189
Update example/hashmaps/example_hashmaps_map_entry.f90
chuckyvt Jul 11, 2024
2b2c290
Update example/hashmaps/example_hashmaps_remove.f90
chuckyvt Jul 11, 2024
0e29642
Update example/hashmaps/example_hashmaps_set_other_data.f90
chuckyvt Jul 11, 2024
3c60ba4
Reverting back to in-line allocation
chuckyvt Jul 11, 2024
7118fc5
Revert "Reverting back to in-line allocation"
chuckyvt Jul 11, 2024
624a7c8
Reapply "Reverting back to in-line allocation"
chuckyvt Jul 12, 2024
0df1d81
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 12, 2024
9415a37
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 15, 2024
351e628
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 16, 2024
3e7337e
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 16, 2024
4bd0bb4
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 16, 2024
bf3c90d
Set_other CI fix
chuckyvt Jul 16, 2024
2ae0d6d
Update set_other again
chuckyvt Jul 16, 2024
937cade
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 17, 2024
873a6de
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 17, 2024
e6296c8
Revert "Update stdlib_hashmap_chaining.f90"
chuckyvt Jul 17, 2024
f7d35c5
Revert "Update stdlib_hashmap_chaining.f90"
chuckyvt Jul 17, 2024
ef1d924
Merge branch 'master' into remove_other_type
chuckyvt Aug 31, 2024
188a74c
Update stdlib_hashmaps.f90
chuckyvt Aug 31, 2024
fbce81f
Revert "Update stdlib_hashmaps.f90"
chuckyvt Sep 4, 2024
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
228 changes: 67 additions & 161 deletions doc/specs/stdlib_hashmaps.md

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions example/hashmaps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
ADD_EXAMPLE(hashmaps_calls)
ADD_EXAMPLE(hashmaps_copy_key)
ADD_EXAMPLE(hashmaps_copy_other)
ADD_EXAMPLE(hashmaps_entries)
ADD_EXAMPLE(hashmaps_equal_keys)
ADD_EXAMPLE(hashmaps_fnv_1a_hasher)
ADD_EXAMPLE(hashmaps_fnv_1_hasher)
ADD_EXAMPLE(hashmaps_free_key)
ADD_EXAMPLE(hashmaps_free_other)
ADD_EXAMPLE(hashmaps_get)
ADD_EXAMPLE(hashmaps_get_all_keys)
ADD_EXAMPLE(hashmaps_get_other_data)
Expand Down
22 changes: 0 additions & 22 deletions example/hashmaps/example_hashmaps_copy_other.f90

This file was deleted.

18 changes: 0 additions & 18 deletions example/hashmaps/example_hashmaps_free_other.f90

This file was deleted.

12 changes: 4 additions & 8 deletions example/hashmaps/example_hashmaps_get_all_keys.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ program example_hashmaps_get_all_keys
use stdlib_kinds, only: int32
use stdlib_hashmaps, only: chaining_hashmap_type
use stdlib_hashmap_wrappers, only: fnv_1_hasher, get, &
key_type, other_type, set
key_type, set
implicit none
type(chaining_hashmap_type) :: map
type(key_type) :: key
type(other_type) :: other

type(key_type), allocatable :: keys(:)
integer(int32) :: i
Expand All @@ -17,16 +16,13 @@ program example_hashmaps_get_all_keys

! adding key-value pairs to the map
call set(key, "initial key")
call set(other, "value 1")
call map%map_entry(key, other)
call map%map_entry(key, "value 1")

call set(key, "second key")
call set(other, "value 2")
call map%map_entry(key, other)
call map%map_entry(key, "value 2")

call set(key, "last key")
call set(other, "value 3")
call map%map_entry(key, other)
call map%map_entry(key, "value 3")

! getting all the keys in the map
call map%get_all_keys(keys)
Expand Down
38 changes: 19 additions & 19 deletions example/hashmaps/example_hashmaps_get_other_data.f90
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
program example_get_other_data
use stdlib_kinds, only: int8, int64
use stdlib_hashmaps, only: chaining_hashmap_type, int_index
use stdlib_hashmap_wrappers, only: fnv_1_hasher, key_type, other_type, set, get
use stdlib_hashmap_wrappers, only: fnv_1_hasher, key_type, set, get
implicit none
logical :: conflict
type(key_type) :: key
type(other_type) :: other
type(chaining_hashmap_type) :: map
type dummy_type
integer :: value(4)
Expand All @@ -21,17 +20,18 @@ program example_get_other_data
! Hashmap functions are setup to store scalar value types (other). Use a dervied
! type wrapper to store arrays.
dummy%value = [4, 3, 2, 1]
call set(other, dummy)

! Explicitly set key type using set function
call set(key, [0, 1])
call map%map_entry(key, other, conflict)
call map%map_entry(key, dummy, conflict)
if (.not. conflict) then
call map%get_other_data(key, other)
call map%get_other_data(key, data)
else
error stop 'Key is already present in the map.'
end if
call get(other, data)

! Get_other_data returns data as an unlimited polymorphic scalar.
! To use this type in other operations, there must be a select type operation.
select type (data)
type is (dummy_type)
print *, 'Other data % value = ', data%value
Expand All @@ -41,29 +41,29 @@ program example_get_other_data

! Also can use map_entry and get_other_data generic key interfaces.
! This is an exmple with integer arrays.
call map%map_entry( [2,3], other, conflict)
call map%map_entry( [2,3], dummy, conflict)
if (.not. conflict) then
call map%get_other_data( [2,3], other)
call map%get_other_data( [2,3], data)
else
error stop 'Key is already present in the map.'
end if
call get(other, data)

select type (data)
type is (dummy_type)
print *, 'Other data % value = ', data%value
class default
print *, 'Invalid data type in other'
end select

! Integer scalars need to be passed as an array.
! Integer scalar keys need to be passed as an array.
int_scalar = 2
call map%map_entry( [int_scalar], other, conflict)
call map%map_entry( [int_scalar], dummy, conflict)
if (.not. conflict) then
call map%get_other_data( [int_scalar], other)
call map%get_other_data( [int_scalar], data)
else
error stop 'Key is already present in the map.'
end if
call get(other, data)

select type (data)
type is (dummy_type)
print *, 'Other data % value = ', data%value
Expand All @@ -72,13 +72,13 @@ program example_get_other_data
end select

! Example using character type key interface
call map%map_entry( 'key_string', other, conflict)
call map%map_entry( 'key_string', dummy, conflict)
if (.not. conflict) then
call map%get_other_data( 'key_string', other)
call map%get_other_data( 'key_string', data)
else
error stop 'Key is already present in the map.'
end if
call get(other, data)

select type (data)
type is (dummy_type)
print *, 'Other data % value = ', data%value
Expand All @@ -88,13 +88,13 @@ program example_get_other_data

! Transfer to int8 arrays to generate key for unsupported types.
key_array = transfer( [0_int64, 1_int64], [0_int8] )
call map%map_entry( key_array, other, conflict)
call map%map_entry( key_array, dummy, conflict)
if (.not. conflict) then
call map%get_other_data( key_array, other)
call map%get_other_data( key_array, data)
else
error stop 'Key is already present in the map.'
end if
call get(other, data)

select type (data)
type is (dummy_type)
print *, 'Other data % value = ', data%value
Expand Down
30 changes: 20 additions & 10 deletions example/hashmaps/example_hashmaps_map_entry.f90
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
program example_map_entry
use, intrinsic:: iso_fortran_env, only: int8, int64
use stdlib_hashmaps, only: chaining_hashmap_type
use stdlib_hashmap_wrappers, only: fnv_1_hasher, key_type, other_type, set
use stdlib_hashmap_wrappers, only: fnv_1_hasher, key_type, set
implicit none
type(chaining_hashmap_type) :: map
type(key_type) :: key
logical :: conflict
type(other_type) :: other
integer :: int_scalar

type :: array_data_wrapper
integer, allocatable :: array(:)
end type

type(array_data_wrapper) :: array_example

! Initialize hashmap with 2^10 slots.
! Hashmap will dynamically increase size if needed.
call map%init(fnv_1_hasher, slots_bits=10)
! Initialize other type with data to store.
call set(other, 4)

! Explicitly set key using set function
call set(key, [1, 2, 3])
call map%map_entry(key, other, conflict)
call map%map_entry(key, 4, conflict)
print *, 'CONFLICT = ', conflict

! Using map_entry int32 array interface
call map%map_entry( [4, 5, 6], other, conflict)
call map%map_entry( [4, 5, 6], 4, conflict)
print *, 'CONFLICT = ', conflict

! Integer scalars need to be passed as an array.
int_scalar = 1
call map%map_entry( [int_scalar], other, conflict)
call map%map_entry( [int_scalar], 4, conflict)
print *, 'CONFLICT = ', conflict

! Using map_entry character interface
call map%map_entry( 'key_string', other, conflict)
call map%map_entry( 'key_string', 4, conflict)
print *, 'CONFLICT = ', conflict

! Transfer unsupported key types to int8 arrays.
call map%map_entry( transfer( [1_int64, 2_int64, 3_int64], [0_int8] ), other, conflict)
call map%map_entry( transfer( [1_int64, 2_int64, 3_int64], [0_int8] ), 4, conflict)
print *, 'CONFLICT = ', conflict

! Keys can be mapped alone without a corresponding value (other).
! Keys can be mapped alone without a corresponding value (other) for 'Set' type functionality.
call map%map_entry( [7, 8, 9], conflict=conflict)
print *, 'CONFLICT = ', conflict

! Currently only scalar data can be mapped.
! Arrays will need a wrapper.
array_example % array = [1,2,3,4,5]
call map % map_entry( [10,11,12], array_example, conflict=conflict )
print *, 'CONFLICT = ', conflict

end program example_map_entry
8 changes: 2 additions & 6 deletions example/hashmaps/example_hashmaps_rehash.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ program example_rehash
use stdlib_kinds, only: int8
use stdlib_hashmaps, only: open_hashmap_type
use stdlib_hashmap_wrappers, only: fnv_1_hasher, fnv_1a_hasher, &
key_type, other_type, set
key_type, set
implicit none
type(open_hashmap_type) :: map
type(key_type) :: key
type(other_type) :: other
class(*), allocatable :: dummy
allocate (dummy, source='a dummy value')
call map%init(fnv_1_hasher, slots_bits=10)
call set(key, [5_int8, 7_int8, 4_int8, 13_int8])
call set(other, dummy)
call map%map_entry(key, other)
call map%map_entry(key, 'A value')
call map%rehash(fnv_1a_hasher)
end program example_rehash
17 changes: 6 additions & 11 deletions example/hashmaps/example_hashmaps_remove.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,40 @@ program example_remove
use stdlib_kinds, only: int8, int64
use stdlib_hashmaps, only: open_hashmap_type, int_index
use stdlib_hashmap_wrappers, only: fnv_1_hasher, &
fnv_1a_hasher, key_type, other_type, set
fnv_1a_hasher, key_type, set
implicit none
type(open_hashmap_type) :: map
type(key_type) :: key
type(other_type) :: other
logical :: existed
integer :: int_scalar

! Initialize hashmap with 2^10 slots.
! Hashmap will dynamically increase size if needed.
call map%init(fnv_1_hasher, slots_bits=10)

! Initialize other type with data to store.
call set(other, 4.0)

! Explicitly set key type using set function
call set(key, [1, 2, 3])
call map%map_entry(key, other)
call map%map_entry(key, 4.0)
call map%remove(key, existed)
print *, "Removed key existed = ", existed

! Using map_entry and remove int32 generic interface.
call map%map_entry([1, 2, 3], other)
call map%map_entry([1, 2, 3], 4.0)
call map%remove([1, 2, 3], existed)
print *, "Removed key existed = ", existed

! Integer scalars need to be passed as an array.
int_scalar = 1
call map%map_entry( [int_scalar], other)
call map%map_entry( [int_scalar], 4.0)
call map%remove( [int_scalar], existed)
print *, "Removed key existed = ", existed

! Using map_entry and remove character generic interface.
call map%map_entry('key_string', other)
call map%map_entry('key_string', 4.0)
call map%remove('key_string', existed)
print *, "Removed key existed = ", existed

! Use transfer to int8 arrays for unsupported key types.
call map%map_entry( transfer( [1_int64, 2_int64], [0_int8] ), other)
call map%map_entry( transfer( [1_int64, 2_int64], [0_int8] ), 4.0)
call map%remove( transfer( [1_int64,2_int64], [0_int8] ), existed)
print *, "Removed key existed = ", existed
end program example_remove
34 changes: 24 additions & 10 deletions example/hashmaps/example_hashmaps_set_other_data.f90
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
program example_set_other_data
use stdlib_kinds, only: int8
use stdlib_hashmaps, only: open_hashmap_type
use stdlib_hashmap_wrappers, only: fnv_1_hasher, &
fnv_1a_hasher, key_type, other_type, set
use stdlib_hashmaps, only: open_hashmap_type, chaining_hashmap_type
use stdlib_hashmap_wrappers, only: key_type, set, fnv_1_hasher

implicit none
logical :: exists
type(open_hashmap_type) :: map
type(key_type) :: key
type(other_type) :: other
type(chaining_hashmap_type) :: map
class(*), allocatable :: data
type(key_type) :: key

! Initialize hashmap with 2^10 slots.
! Hashmap will dynamically increase size if needed.
call map%init(fnv_1_hasher, slots_bits=10)

call set(key, [5, 7, 4, 13])
call set(other, 'A value')
call map%map_entry(key, other)

call set(other, 'Another value')
call map%set_other_data(key, other, exists)
call map%map_entry(key, 'A value')

call map%set_other_data(key, 'Another value', exists)

print *, 'The entry to have its other data replaced exists = ', exists

call map%get_other_data(key, data, exists)

print *, 'Get_other_data was successful = ', exists

! Hashmaps return an unlimited polymorphic type as other.
! Must be included in a select type operation to do further operations.
select type (data)
type is (character(*))
print *, 'Value is = ', data
class default
print *, 'Invalid data type in other'
end select

end program example_set_other_data
Loading
Loading