djb2 Function

public function djb2(anything)

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: anything(:)

Return Value integer(kind=int128)


Source Code

function djb2(anything)
implicit none

! ident_10="@(#) djb2(3f) call C routine djb2(3c) with a Fortran CHARACTER variable"

! extern int djb2(char *s);
interface
   function djb2_F(S) bind(C,NAME='C_djb2')
      use ISO_C_BINDING, only : C_LONG, C_CHAR
      implicit none
      integer(KIND=C_LONG)              :: djb2_F
      character(KIND=C_CHAR),intent(in) :: S(*)
   end function djb2_F
end interface

class(*),intent(in)          :: anything(:)
integer(kind=int128)         :: djb2
character(len=1),allocatable :: chars(:)

   chars=anything_to_bytes(anything)

   djb2=transfer([djb2_F([chars,char(0)]),0_int64],djb2)

   if(debug)then
      DEBUG : block
      integer :: i
      integer :: ios
      write(6,'("*djb2 FORTRAN*        hashing string=",*(a))',advance='no')(chars(i),i=1,size(chars))
      write(6,'(1x,"hash=",i0,1x,"hex hash=",z32.32)')djb2,djb2
      flush(6,iostat=ios)
      endblock DEBUG
   endif

end function djb2