fibonacci_hash 函数

public elemental function fibonacci_hash(key, nbits) result(sample)

将 32 位整数 key 映射到一个仅包含 nbits 位的无符号整数值,其中 nbits 小于 32 (规范)

参数

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

返回值 integer(kind=int32)


源代码

    elemental function fibonacci_hash( key, nbits ) result( sample )
!! Version: experimental
!!
!! Maps 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#fibonacci_hash-maps-an-integer-to-a-smaller-number-of-bits))

        integer(int32), intent(in) :: key
        integer, intent(in)        :: nbits
        integer(int32)             :: sample

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

    end function fibonacci_hash