program assgin7_3b
implicit none
integer :: hashves,widen,iad,maxid
integer , allocatable :: indb(:,:)
character (12) :: iiden
character (1) :: regnum(12)

equivalence(regnum,iiden)

allocate(idcow(maxcow),idbull(maxbull),indc(maxcow,3),indb(maxbull,3))
endif
!read bull id and locate in hash table if the file exist
do i=1,int(maxbull/1000)+1
read(39,iostat=k2)(idbull(j),j=1+(i-1)*1000,min(i*1000,maxbull))
enddo

widen=transfer(iiden,widen)
iad=hashves(widen,3,indb,maxid,3,1,nr)

 

end program assgin7_3b

 

interface !external function
function hashvr(dat,r,ind,m,n,mode,nr)
use kinds
integer ::hashvr,r,mode,nr,m,n
real (rh)::ind(:,:),dat(r)
end function
end interface

integer :: full

full=hashvr((/real(i,rh),real(j,rh)/),2,x%x,x%nel,3,1,x%filled)

integer function hashvr(dat,r,ind,m,n,mode,nr)
c returns address of element of ind() containing real vector dat.
c Searching goes with a HASH technique. When mode=1 and dat was not
c there before, dat is written into ind("hash",1..r). When mod=0
c and dat is not found, this function returns 0.
c rank of ind is m x n,
c dat contains r numbers.
c !! same as hashvec except that rows and columns switched !!
c !! same as hashves except that on low memory returns -1 and reals
use kinds
integer r,mode,nr,m,n
real (rh) :: ind(:,:),dat(r)
integer(i8):: iaddr
integer prime(10),ie,iaddress,k,izer,ieq,i1,i
data ie/17/,prime/433,1039,53,761,197,31,887,389,277,97/
c
iaddr=0
do i=1,r
iaddr=iaddr+prime(i)*dat(i)
enddo
iaddress=abs(mod(iaddr, int(m,kind(iaddr)) ))+1

do k=1,5000
izer=0
ieq=0
do i=1,r
i1=ind(i,iaddress)
if (i1.ne.dat(i)) ieq=1
if (ind(i,iaddress).ne.0) izer=1
enddo

if (izer.eq.0 .or. ieq.eq.0) then
if (izer.eq.0 .and. mode.eq.1) then
do i=1,r
ind(i,iaddress)=dat(i)
enddo
nr=nr+1
endif
if (mode.eq.0 .and.izer.eq.0) then
hashvr=0
else
hashvr=iaddress
endif
return
endif
iaddress=mod(iaddress+ie-1,m)+1
enddo

hashvr=-1
return
end