Skip to content

Commit

Permalink
Merge pull request #778 from chuckyvt/hashmap_int32_key
Browse files Browse the repository at this point in the history
Update to include int32 hashmap keytype
  • Loading branch information
jvdp1 authored Apr 25, 2024
2 parents 19f84ce + f35386f commit f44133b
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 72 deletions.
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 )

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

0 comments on commit f44133b

Please sign in to comment.