HASH: Rewrite internal xxh64() to accept pointer instead of array.

Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
Grzegorz Kowal 2021-11-30 12:59:43 -03:00
parent b5183dfa0e
commit 398b3e331d

View File

@ -195,25 +195,22 @@ module hash
!
integer(kind=8) function digest(input, hash_type) result(hash)
#ifdef XXHASH
use iso_c_binding, only: c_loc
#endif /* XXHASH */
implicit none
integer(kind=1), dimension(:), target, intent(in) :: input
integer , intent(in) :: hash_type
#ifdef XXHASH
integer(kind=8) :: length
#endif /* XXHASH */
!-------------------------------------------------------------------------------
!
select case(hash_type)
case(hash_xxh64)
#ifndef XXHASH
hash = xxh64(input)
length = size(input, kind=8)
hash = xxh64(c_loc(input), length)
#else /* XXHASH */
length = size(input, kind=8)
hash = xxh64_lib(c_loc(input), length, 0_8)
@ -354,24 +351,30 @@ module hash
!
! Arguments:
!
! input - the input sequence of bytes;
! buffer - the buffer pointer;
! length - the buffer length;
!
!===============================================================================
!
integer(kind=8) function xxh64(input) result(hash)
integer(kind=8) function xxh64(buffer, length) result(hash)
use iso_c_binding, only: c_ptr, c_f_pointer
implicit none
integer(kind=1), dimension(:), target, intent(in) :: input
type(c_ptr) , intent(in) :: buffer
integer(kind=8), intent(in) :: length
integer(kind=8) :: length
integer(kind=8) :: remaining, offset
integer(kind=8), dimension(4) :: lane, chunk
integer(kind=1), dimension(:), pointer :: input
!-------------------------------------------------------------------------------
!
length = size(input, kind=8)
call c_f_pointer(buffer, input, [ length ])
hash = 0_8
offset = 1_8
remaining = length