hash.f90 Source File


This file depends on

sourcefile~~hash.f90~~EfferentGraph sourcefile~hash.f90 hash.f90 sourcefile~kinds.f90 kinds.f90 sourcefile~hash.f90->sourcefile~kinds.f90

Files dependent on this one

sourcefile~~hash.f90~~AfferentGraph sourcefile~hash.f90 hash.f90 sourcefile~datastructs_mod.f90 datastructs_mod.f90 sourcefile~datastructs_mod.f90->sourcefile~hash.f90

Source Code

module datastructs_hash_mod
    use datastructs_kinds_mod
    implicit none
    private

    public :: djb2

contains

    !> DJB2 hash function
    !> Inspired by:
    !> - http://www.cse.yorku.ca/~oz/hash.html
    !> - https://github.com/pdebuyl/fortran_hash_table/blob/master/src/dictionary_m.f90
    function djb2(list) result(r)
        integer(kind=i4), intent(in) :: list(:) !! List of integers to hash
        integer(kind=i8) :: r !! Computed hash value

        integer(kind=i4) :: i !! Loop index
        integer(kind=i4) :: l !! Length of the list

        l = size(list)

        r = 5381_i8

        do i = 1, l
            r = (ishft(r, 5) + r) + int(list(i), i8)
        end do

    end function djb2

end module datastructs_hash_mod