fhash_fnv Module

A module for Fowler–Noll–Vo (FNV) hashing

Implements the FNV 1a algorithm for 32bit hashes

Supports hashing of: - 32bit integers (scalar & 1D array) - 64bit integers (scalar & 1D array) - character(*), default kind

The lack of unsigned arithmetic in Fortran means that 64bit arithmetic is needed to perform 32bit hashing. Hashes are therefore returned as int64.



Contents


Interfaces

public interface fnv_1a

Generic interface to perform hashing

Usage:

 fnv_1a([seed],input)

where input is any of the supported types

  • private pure function fnv_1a_char_scalar(input) result(hash)

    Hash a single default kind character variable

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: input

    Return Value integer(kind=int64)

  • private pure function fnv_1a_char_scalar_seed(seed, input) result(hash)

    Hash a character(*) string of default kind

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: seed
    character(len=*), intent(in) :: input

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int32_scalar(input) result(hash)

    Hash a single 32bit integer

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: input

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int32_scalar_seed(seed, input) result(hash)

    Hash a single 32bit integer with a starting seed

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: seed
    integer(kind=int32), intent(in) :: input

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int32_1d(input) result(hash)

    Hash a 1D array of 32bit integers

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: input(:)

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int32_1d_seed(seed, input) result(hash)

    Hash a 1D array of 32bit integers with a starting seed

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: seed
    integer(kind=int32), intent(in) :: input(:)

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int64_scalar(input) result(hash)

    Hash a single 64bit integer

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: input

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int64_scalar_seed(seed, input) result(hash)

    Hash a single 64bit integer with a starting seed

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: seed
    integer(kind=int64), intent(in) :: input

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int64_1d(input) result(hash)

    Hash a 1D array of 64bit integers

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: input(:)

    Return Value integer(kind=int64)

  • private pure function fnv_1a_int64_1d_seed(seed, input) result(hash)

    Hash a 1D array of 64bit integers with a starting seed

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int64), intent(in) :: seed
    integer(kind=int64), intent(in) :: input(:)

    Return Value integer(kind=int64)


Functions

public function hash_string(hash_value) result(str)

Help fcn to convert hash to hex representation

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: hash_value

Return Value character(len=:), allocatable