Odile
Odile

Reputation: 33

assign value to key in hash code in Fortran

I am trying to implement a hash table in my Fortran code and I have found an example on the Internet, but I can't figure out how the value is assigned to the key.

The following link redirects to the Fortran module I want to implement with a example on how to use the code.

http://didgeridoo.une.edu.au/womwiki/doku.php?id=fortran:fortran

Could anyone explain me how to assign a value to the key's in this example program?

Upvotes: 0

Views: 330

Answers (1)

Yossarian
Yossarian

Reputation: 5471

The example program on that page shows how to use it:

 call hash_it(idorig, 1, idnew, ipos, .false.)

! call hash_it(idorig, ivar, idnew, ipos, noadd)
!    idorig = ID to be recoded
!    ivar   = list no. (1, 2, ..., mlists)
!    idnew  = new ID
!    ipos   = position in hash table (rarely used)
!    noadd  = option: .false. adds new IDs
!                     .true.  does not add new IDs, just looks up position

idorig is the (integer) value to be stored, and idnew is the (integer) key. You can then lookup idnew in hlist.

This implementation can only store integers, and uses the hash of the value as the key, i.e. you can't specify the key yourself. If this doesn't suit your needs, you may also want to look at the answers to this question, or on the Fortran wiki.

Upvotes: 2

Related Questions