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 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1c681d1
RC1
chuckyvt Jun 30, 2024
4847f5c
Other_type cleanup and removal
chuckyvt Jul 3, 2024
9c5574b
Update src/stdlib_hashmap_chaining.f90
chuckyvt Jul 3, 2024
72f66b9
Update src/stdlib_hashmap_open.f90
chuckyvt Jul 3, 2024
b09a1ad
Update src/stdlib_hashmap_chaining.f90
chuckyvt Jul 3, 2024
b1cfb3b
Remove other type from test_chaining and test_open
chuckyvt Jul 3, 2024
2ae6665
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 3, 2024
1cd2e2e
Update example_hashmaps_set_other_data.f90
chuckyvt Jul 3, 2024
5692eae
Update CMakeLists.txt
chuckyvt Jul 4, 2024
4a2200f
Update CMakeLists.txt
chuckyvt Jul 4, 2024
97ac470
Update CMakeLists.txt
chuckyvt Jul 4, 2024
45f6f2a
Revert "Update CMakeLists.txt"
chuckyvt Jul 4, 2024
df94ee5
Update CMakeLists.txt
chuckyvt Jul 4, 2024
970e389
Update example_hashmaps_set_other_data.f90
chuckyvt Jul 4, 2024
4b6d682
Update stdlib_hashmaps.md
chuckyvt Jul 7, 2024
8a1b4fa
Update to remove other_type references
chuckyvt Jul 10, 2024
61c1082
Update example_hashmaps_map_entry.f90
chuckyvt Jul 10, 2024
f7a6846
Update example_hashmaps_rehash.f90
chuckyvt Jul 10, 2024
aa9952e
Update example_hashmaps_remove.f90
chuckyvt Jul 10, 2024
9c8f7c2
Test allocate again
chuckyvt Jul 10, 2024
d83e555
Update to include allocate statement
chuckyvt Jul 10, 2024
0485d71
Typo fix
chuckyvt Jul 10, 2024
04e59c0
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
27b7178
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
4d9c68e
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
da075e8
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 11, 2024
e4f1556
Update example/hashmaps/CMakeLists.txt
chuckyvt Jul 11, 2024
1e33189
Update example/hashmaps/example_hashmaps_get_other_data.f90
chuckyvt Jul 11, 2024
c02421a
Update example/hashmaps/example_hashmaps_map_entry.f90
chuckyvt Jul 11, 2024
6228b58
Update example/hashmaps/example_hashmaps_remove.f90
chuckyvt Jul 11, 2024
5b2e71a
Update example/hashmaps/example_hashmaps_set_other_data.f90
chuckyvt Jul 11, 2024
ac93bca
Reverting back to in-line allocation
chuckyvt Jul 11, 2024
07febc3
Revert "Reverting back to in-line allocation"
chuckyvt Jul 11, 2024
4c453a0
Reapply "Reverting back to in-line allocation"
chuckyvt Jul 12, 2024
33ecef2
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 12, 2024
30f2210
Update doc/specs/stdlib_hashmaps.md
chuckyvt Jul 15, 2024
d06e047
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 16, 2024
8c562e4
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 16, 2024
482776d
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 16, 2024
56d9b9e
Set_other CI fix
chuckyvt Jul 16, 2024
03a9351
Update set_other again
chuckyvt Jul 16, 2024
a2bee26
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 17, 2024
4cb9c4d
Update stdlib_hashmap_chaining.f90
chuckyvt Jul 17, 2024
32ba12d
Revert "Update stdlib_hashmap_chaining.f90"
chuckyvt Jul 17, 2024
cc14840
Revert "Update stdlib_hashmap_chaining.f90"
chuckyvt Jul 17, 2024
4120ec7
Update stdlib_hashmaps.f90
chuckyvt Aug 31, 2024
250252d
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
40 changes: 20 additions & 20 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
use stdlib_hashmap_wrappers, only: fnv_1_hasher, key_type, other_type, set, get
use stdlib_hashmaps, only: chaining_hashmap_type, int_index
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
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
35 changes: 25 additions & 10 deletions example/hashmaps/example_hashmaps_set_other_data.f90
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
program example_set_other_data
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_kinds, only: int8
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