MAPL_HashMod
Author: GMAO SI-Team
MAPL_HashMod
– A utility to manage hash tables.
MAPL_HashMod
is a FORTRAN binding to a simple C has facility.
The API is:
! Create a hash table with Nbuckets
integer function MAPL_HashCreate(Nbuckets)
integer, intent(IN) :: Nbuckets
! Update table Hash with integer[s] i[,j]
! The return value is the order of occurence of the integer[s].
! If i is new, the return value is the new hash size.
integer function MAPL_HashIncrement(Hash,i,j)
integer, intent(IN) :: Hash
integer, intent(IN) :: i
integer, optional, intent(IN) :: j
! Dump the list of integers or integer pairs in the hash.
! The list is in no particular order.
! If the arrays are not long enough, nothing is dumped and -1
! is returned; otherwise it returns the current hash size
! (the length of the list).
integer function MAPL_HashDump(Hash,i,j)
integer, intent(IN) :: Hash
integer, intent(OUT) :: i(:)
integer, optional, intent(OUT) :: j(:)
! Get the size of a hash
integer function MAPL_HashSize(Hash)
integer, intent(IN) :: Hash
! Destroy a hash table
subroutine MAPL_HashDestroy(Hash)
integer, intent(IN) :: Hash
The following is a sample usage that makes a list of unique integers in the large array II. It can similarly be used to find ordered pairs of integers. The asserts are put in to clarify the usage.
integer :: Hash, k, II(100000), FoundOrder(10000)
Hash = MAPL_HashCreate(1000)
latest = 0
do i=1,100000
k = MAPL_HashIncrement(Hash,ii(i))
if(k>latest) then
latest = k
isnew = .true.
FoundOrder(k) = ii(i)
if(MAPL_Assert(k==MAPL_HashSize(Hash),'needs informative message',1,"/home/runner/work/MAPL/MAPL/shared/MAPL_Hash.F90",76 ,rc)) return
else
isnew = .false.
if(MAPL_Assert(FoundOrder(k)==ii(i),'needs informative message',1,"/home/runner/work/MAPL/MAPL/shared/MAPL_Hash.F90",79 ,rc)) return
endif
enddo
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | Nbuckets |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | Hash | |||
integer, | intent(out) | :: | i(:) | |||
integer, | intent(out), | optional | :: | j(:) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | Hash | |||
integer, | intent(in) | :: | i | |||
integer, | intent(in), | optional | :: | j | ||
integer, | intent(in), | optional | :: | k |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | Hash |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | Hash |