Merged changes for new hash implementation.

MixedI8
Salvatore Filippone 8 years ago
parent d099c19d89
commit b71fb5e122

@ -1,6 +1,6 @@
include ../../Make.inc
BASIC_MODS= psb_const_mod.o psb_error_mod.o psb_realloc_mod.o \
BASIC_MODS= psb_const_mod.o psb_cbind_const_mod.o psb_error_mod.o psb_realloc_mod.o \
auxil/psb_m_realloc_mod.o \
auxil/psb_e_realloc_mod.o \
auxil/psb_s_realloc_mod.o \
@ -25,7 +25,7 @@ COMMINT=penv/psi_comm_buffers_mod.o penv/psi_penv_mod.o \
UTIL_MODS = auxil/psb_string_mod.o desc/psb_desc_const_mod.o desc/psb_indx_map_mod.o\
desc/psb_gen_block_map_mod.o desc/psb_list_map_mod.o desc/psb_repl_map_mod.o\
desc/psb_glist_map_mod.o desc/psb_hash_map_mod.o \
desc/psb_glist_map_mod.o desc/psb_hash_map_mod.o desc/hashval.o \
desc/psb_desc_mod.o auxil/psb_sort_mod.o \
serial/psb_s_serial_mod.o serial/psb_d_serial_mod.o \
serial/psb_c_serial_mod.o serial/psb_z_serial_mod.o \
@ -266,6 +266,7 @@ desc/psb_hash_map_mod.o desc/psb_list_map_mod.o desc/psb_repl_map_mod.o desc/psb
desc/psb_glist_map_mod.o: desc/psb_list_map_mod.o
desc/psb_hash_map_mod.o: desc/psb_hash_mod.o auxil/psb_sort_mod.o
desc/psb_gen_block_map_mod.o: desc/psb_hash_mod.o
desc/psb_hash_mod.o: psb_cbind_const_mod.o
psb_check_mod.o: desc/psb_desc_mod.o

@ -0,0 +1,49 @@
#include <stdint.h>
/*
This is based on the djb2 hashing algorithm
see e.g. http://www.cse.yorku.ca/~oz/hash.html
*/
#define IVAL 5381
#define H32MASK 0x7FFFFFFF
#define H64MASK 0x7FFFFFFFFFFFFFFF
#define BMASK 0xFF
int32_t psb_c_hashval_32(int32_t inkey)
{
uint32_t key, val, i;
key = inkey;
val = IVAL;
for (i=0; i<4; i++) {
val = ((val<<5)+val)+(key & BMASK);
key >>= 8;
}
val &= H32MASK;
return(val);
}
int64_t psb_c_hashval_64(int64_t inkey)
{
uint64_t key, val, i;
key = inkey;
val = IVAL;
for (i=0; i<8; i++) {
val = ((val<<5)+val)+(key & BMASK);
key >>= 8;
}
val &= H64MASK;
return(val);
}
int32_t psb_c_hashval_64_32(int64_t inkey)
{
uint32_t key, val, i;
key = inkey;
val = IVAL;
for (i=0; i<8; i++) {
val = ((val<<5)+val)+(key & BMASK);
key >>= 8;
}
val &= H32MASK;
return(val);
}

@ -34,6 +34,7 @@
module psb_hash_mod
use psb_const_mod
use psb_desc_const_mod
use psb_cbind_const_mod
!> \class psb_hash_mod
!! \brief Simple hash module for storing integer keys.
!!
@ -66,6 +67,37 @@ module psb_hash_mod
integer(psb_ipk_), parameter :: HashDuplicate = 123, HashOK=0, HashOutOfMemory=-512,&
& HashFreeEntry = -1, HashNotFound = -256
interface psb_hashval
#if defined(IPK4)
function psb_c_hashval_32(key) bind(c) result(res)
import psb_c_ipk
implicit none
integer(psb_c_ipk), value :: key
integer(psb_c_ipk) :: res
end function psb_c_hashval_32
#endif
#if defined(IPK4) && defined(LPK8)
function psb_c_hashval_64_32(key) bind(c) result(res)
import psb_c_ipk, psb_c_lpk
implicit none
integer(psb_c_lpk), value :: key
integer(psb_c_ipk) :: res
end function psb_c_hashval_64_32
#endif
#if defined(IPK8)
function psb_c_hashval_64(key) bind(c) result(res)
import psb_c_ipk
implicit none
integer(psb_c_ipk), value :: key
integer(psb_c_ipk) :: res
end function psb_c_hashval_64
#endif
end interface psb_hashval
interface psb_hash_init
module procedure psb_hash_init_lv, psb_hash_init_ln
end interface psb_hash_init
@ -74,9 +106,6 @@ module psb_hash_mod
module procedure psb_sizeof_hash_type
end interface
interface hashval
module procedure lhashval
end interface hashval
interface psb_hash_searchinskey
module procedure psb_hash_lsearchinskey
@ -91,10 +120,6 @@ module psb_hash_mod
module procedure psb_hash_init_v, psb_hash_init_n
end interface
interface hashval
module procedure ihashval
end interface hashval
interface psb_hash_searchinskey
module procedure psb_hash_isearchinskey
end interface psb_hash_searchinskey
@ -117,50 +142,6 @@ module psb_hash_mod
end interface
contains
!
! This is based on the djb2 hashing algorithm
! see e.g. http://www.cse.yorku.ca/~oz/hash.html
!
function ihashval(key) result(val)
integer(psb_ipk_), intent(in) :: key
integer(psb_ipk_), parameter :: ival=5381, mask=huge(ival)
integer(psb_ipk_) :: key_, val, i
key_ = key
val = ival
do i=1, psb_sizeof_ip
val = val * 33 + iand(key_,255)
key_ = ishft(key_,-8)
end do
val = val + ishft(val,-5)
val = iand(val,mask)
end function ihashval
!
! This is based on the djb2 hashing algorithm
! see e.g. http://www.cse.yorku.ca/~oz/hash.html
!
function lhashval(key) result(val)
integer(psb_lpk_), intent(in) :: key
integer(psb_ipk_), parameter :: ival=5381, mask=huge(ival)
integer(psb_ipk_) :: val, i
integer(psb_lpk_) :: key_
key_ = key
val = ival
do i=1, psb_sizeof_lp
val = val * 33 + iand(key_,255)
key_ = ishft(key_,-8)
end do
val = val + ishft(val,-5)
val = iand(val,mask)
end function lhashval
function psb_Sizeof_hash_type(hash) result(val)
type(psb_hash_type) :: hash
@ -408,7 +389,7 @@ contains
hsize = hash%hsize
hmask = hash%hmask
hk = iand(hashval(key),hmask)
hk = iand(psb_hashval(key),hmask)
if (hk == 0) then
hd = 1
else
@ -468,7 +449,7 @@ contains
hsize = hash%hsize
hmask = hash%hmask
hk = iand(hashval(key),hmask)
hk = iand(psb_hashval(key),hmask)
if (hk == 0) then
hd = 1
else
@ -531,7 +512,7 @@ contains
end if
hsize = hash%hsize
hmask = hash%hmask
hk = iand(hashval(key),hmask)
hk = iand(psb_hashval(key),hmask)
if (hk == 0) then
hd = 1
else
@ -571,7 +552,7 @@ contains
end if
hsize = hash%hsize
hmask = hash%hmask
hk = iand(hashval(key),hmask)
hk = iand(psb_hashval(key),hmask)
if (hk == 0) then
hd = 1
else

@ -84,7 +84,8 @@ module psb_c_mat_mod
type :: psb_cspmat_type
class(psb_c_base_sparse_mat), allocatable :: a
class(psb_c_base_sparse_mat), allocatable :: a
class(psb_lc_base_sparse_mat), allocatable :: la
contains
! Getters

@ -84,7 +84,8 @@ module psb_d_mat_mod
type :: psb_dspmat_type
class(psb_d_base_sparse_mat), allocatable :: a
class(psb_d_base_sparse_mat), allocatable :: a
class(psb_ld_base_sparse_mat), allocatable :: la
contains
! Getters

@ -84,7 +84,8 @@ module psb_s_mat_mod
type :: psb_sspmat_type
class(psb_s_base_sparse_mat), allocatable :: a
class(psb_s_base_sparse_mat), allocatable :: a
class(psb_ls_base_sparse_mat), allocatable :: la
contains
! Getters

@ -84,7 +84,8 @@ module psb_z_mat_mod
type :: psb_zspmat_type
class(psb_z_base_sparse_mat), allocatable :: a
class(psb_z_base_sparse_mat), allocatable :: a
class(psb_lz_base_sparse_mat), allocatable :: la
contains
! Getters

@ -1,22 +1,6 @@
module psb_objhandle_mod
use iso_c_binding
integer, parameter :: psb_c_mpk = c_int32_t
#if defined(IPK4) && defined(LPK4)
integer, parameter :: psb_c_ipk = c_int32_t
integer, parameter :: psb_c_lpk = c_int32_t
#elif defined(IPK4) && defined(LPK8)
integer, parameter :: psb_c_ipk = c_int32_t
integer, parameter :: psb_c_lpk = c_int64_t
#elif defined(IPK8) && defined(LPK8)
integer, parameter :: psb_c_ipk = c_int64_t
integer, parameter :: psb_c_lpk = c_int64_t
#else
integer, parameter :: psb_c_ipk = -1
integer, parameter :: psb_c_lpk = -1
#endif
integer, parameter :: psb_c_epk = c_int64_t
use psb_cbind_const_mod
type, bind(c) :: psb_c_object_type
type(c_ptr) :: item = c_null_ptr

Loading…
Cancel
Save