Hash a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | string | The string. |
||
integer(kind=I4P), | intent(in) | :: | buckets_number | Buckets number. |
Bucket index corresponding to the string.
elemental function hash_string(string, buckets_number) result(bucket)
!---------------------------------------------------------------------------------------------------------------------------------
!< Hash a string.
!---------------------------------------------------------------------------------------------------------------------------------
character(*), intent(in) :: string !< The string.
integer(I4P), intent(in) :: buckets_number !< Buckets number.
integer(I8P) :: bucket !< Bucket index corresponding to the string.
integer(I4P) :: c !< Counter.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
bucket = int(buckets_number, I8P)
do c=1, len(string)
bucket = (ishft(bucket, 5) + bucket) + ichar(string(c:c), kind=I8P)
enddo
!---------------------------------------------------------------------------------------------------------------------------------
endfunction hash_string