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

Update to include int32 hashmap keytype #778

Merged
merged 14 commits into from
Apr 25, 2024
21 changes: 12 additions & 9 deletions doc/specs/stdlib_hashmaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ Procedures to manipulate `key_type` data:
`key_in`, to contents of the key, `key_out`.

* `get( key, value )` - extracts the contents of `key` into `value`,
an `int8` array or character string.
an `int8` array, 'int32' array, or character string.

* `free_key( key )` - frees the memory in `key`.

* `set( key, value )` - sets the content of `key` to `value`.
* `set( key, value )` - sets the content of `key` to `value`.
Supported key types are `int8` array, `int32` array, and character
string.

Procedures to manipulate `other_type` data:

Expand Down Expand Up @@ -474,9 +476,9 @@ is an `intent(in)` argument.

`value`: if the the first argument is of `key_type` `value` shall be
an allocatable default character string variable, or
an allocatable vector variable of type integer and kind `int8`,
otherwise the first argument is of `other_type` and `value` shall be
an allocatable of `class(*)`. It is an `intent(out)` argument.
an allocatable vector variable of type integer and kind `int8` or
`int32`, otherwise the first argument is of `other_type` and `value`
shall be an allocatable of `class(*)`. It is an `intent(out)` argument.

##### Example

Expand Down Expand Up @@ -751,13 +753,14 @@ is an `intent(out)` argument.

`value`: if the first argument is `key` `value` shall be a default
character string scalar expression, or a vector expression of type integer
and kind `int8`, while for a first argument of type `other` `value`
shall be of type `class(*)`. It is an `intent(in)` argument.
and kind `int8` or `int32`, while for a first argument of type
`other` `value` shall be of type `class(*)`. It is an `intent(in)`
argument.

##### Note

Values of types other than a scalar default character or an
`int8` vector can be used as the basis of a `key` by transferring the
Values of types other than a scalar default character or and
`int8` or `int32` vector can be used as the basis of a `key` by transferring the
value to an `int8` vector.

##### Example
Expand Down
32 changes: 32 additions & 0 deletions src/stdlib_hashmap_wrappers.f90
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ end function hasher_fun

module procedure get_char_key, &
get_int8_key, &
get_int32_key, &
get_other

end interface get
Expand All @@ -101,6 +102,7 @@ end function hasher_fun

module procedure set_char_key, &
set_int8_key, &
set_int32_key, &
set_other

end interface set
Expand Down Expand Up @@ -277,6 +279,21 @@ subroutine get_int8_key( key, value )
end subroutine get_int8_key


pure subroutine get_int32_key( key, value )
!! Version: Experimental
!!
!! Gets the contents of the key as an INTEGER(INT32) vector
!! Arguments:
!! key - the input key
!! value - the contents of key mapped to an INTEGER(INT32) vector
type(key_type), intent(in) :: key
integer(int32), allocatable, intent(out) :: value(:)

value = transfer( key % value, value )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I wonder whether it matters that value is unallocated in the RHS call to transfer (since it will be deallocated on input if allocated)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've asked this question at fortran discourse here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for asking. Intuitively it seems like it shouldn't matter since its only pulling type info, not size. But I also did a quick search and didn't come up with anything. We could hardcode it to [0_int8], but I don't like that quite as much.


end subroutine get_int32_key


subroutine set_char_key( key, value )
!! Version: Experimental
!!
Expand Down Expand Up @@ -323,6 +340,21 @@ subroutine set_int8_key( key, value )
end subroutine set_int8_key


pure subroutine set_int32_key( key, value )
!! Version: Experimental
!!
!! Sets the contents of the key from an INTEGER(INT32) vector
!! Arguments:
!! key - the output key
!! value - the input INTEGER(INT32) vector
type(key_type), intent(out) :: key
integer(int32), intent(in) :: value(:)

key % value = transfer(value, key % value)

end subroutine set_int32_key


pure function fnv_1_hasher( key )
!! Version: Experimental
!!
Expand Down
Loading
Loading