universal_mult_hash 函数

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

使用“随机”奇数 32 位整数 seed 将 32 位整数 key 映射到一个无符号整数,该整数仅有 nbits 位,其中 nbits 小于 32 (规范)

参数

类型 意图可选 属性 名称
integer(kind=int32), intent(in) :: key
integer(kind=int32), intent(in) :: seed
integer, intent(in) :: nbits

返回值 integer(kind=int32)


源代码

    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