fibonacci_hash 函数

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

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

参数

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

返回值 integer(kind=int64)


源代码

    elemental function fibonacci_hash( key, nbits ) result( sample )
!! Version: experimental
!!
!! Maps the 64 bit integer `key` to an unsigned integer value with only `nbits`
!! bits where `nbits` is less than 64
!! ([Specification](../page/specs/stdlib_hash_procedures.html#fibonacci_hash-maps-an-integer-to-a-smaller-number-of-bits_1))

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

        sample = ishft( key*pow64_over_phi, -64 + nbits )

    end function fibonacci_hash