-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_custom_hash_function.f90
More file actions
47 lines (38 loc) · 1.05 KB
/
Copy pathexample_custom_hash_function.f90
File metadata and controls
47 lines (38 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module m_ffhash
use iso_fortran_env
implicit none
#define FFH_STRING_KEY_TYPE character(len=20)
#define FFH_VAL_TYPE integer
#define FFH_CUSTOM_HASH_FUNCTION
#include "ffhash_inc.f90"
! djb2 hash function
pure integer function hash_function(key) result(hash)
character(len=*), intent(in) :: key
integer :: n
hash = 5381
do n = 1, len(key)
! hash * 33 + c
hash = (shiftl(hash, 5) + hash) + iachar(key(n:n))
end do
end function hash_function
end module m_ffhash
program test
use m_ffhash
implicit none
type(ffh_t) :: h
integer :: day, month, year
call h%ustore_value("day", 20)
call h%ustore_value("month", 2)
call h%ustore_value("year", 2020)
call h%uget_value("day", day)
call h%uget_value("month", month)
call h%uget_value("year", year)
if (all([day, month, year] == [20, 2, 2020])) then
print *, [day, month, year]
print *, h%get_index(["day ", "month", "year "])
print *, "PASSED"
else
error stop "FAILED"
end if
call h%reset()
end program test