universal_mult_hash Function

public elemental function universal_mult_hash(key, seed, nbits) result(sample)

Uses the "random" odd 32 bit integer seed to map the 32 bit integer key to an unsigned integer value with only nbits bits where nbits is less than 32 (Specification)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: key
integer(kind=int32), intent(in) :: seed
integer, intent(in) :: nbits

Return Value integer(kind=int32)


Source Code

    elemental function universal_mult_hash( key, seed, nbits ) result( sample )
!! Version: experimental
!!
!! Uses the "random" odd 32 bit integer `seed` to map the 32 bit integer `key` to
!! an unsigned integer value with only `nbits` bits where `nbits` is less than 32
!! ([Specification](../page/specs/stdlib_hash_procedures.html#universal_mult_hash-maps-an-integer-to-a-smaller-number-of-bits))
        integer(int32), intent(in) :: key
        integer(int32), intent(in) :: seed
        integer, intent(in)        :: nbits
        integer(int32)             :: sample

        sample = ishft( key*seed, -32 + nbits )

    end function universal_mult_hash