Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Hash-like data-structure in Fortran [closed]

Is there a library usable in Fortran, which allows the usage of sparse dynamic arrays (hash/dictionary like) besides the Judy arrays?

like image 358
haraldkl Avatar asked Aug 23 '11 08:08

haraldkl


2 Answers

Haven't seen one built-in, but google returns a few:

FLibs: http://flibs.sourceforge.net/

Hash Tables: http://burtleburtle.net/bob/hash/evahash.html and http://www.cris.com/~Ttwang/tech/inthash.htm.

like image 173
SOUser Avatar answered Oct 07 '22 00:10

SOUser


I have created an abstracted dictionary in fortran which might suit your needs.

See: https://github.com/zerothi/fdict

Basically it lets you do

type(dict) :: dic, dic2
dic = ('KEY'.kv.1)
dic = dic //('next'.kv. (/3.,5.,6./))
dic = dic //('string'.kv.'Hello world')
dic2 = ('string2'.kv.'Test')
dic = dic // ('dic2'.kvp.dic2)

Where you can save all intrinsic types and it can easily be extended to contain other data-types, it defaults to initially contain itself as another value. (the last line retains a dictionary as a pointer)

It does .kv. == key : value designation which is a deep copy, and .kvp. == key : pointer which is a reference copy. In this way you can store huge data without having to duplicate data and retrieve the pointer at some later point.

To elaborate on the idea, all data is stored as address pointers using a transfer call from a derived type containing the data pointer. In this way you trick the compiler to hand you the address of the fortran derived type, but forces you to retrieve it in the exact same manner.
By .kv. a pointer of the data-type is allocated and subsequently pointed to by the data-container, then afterwards the allocated pointer is nullifyied and lost thus forcing the user to know what they are doing (there is no garbage-collector in it ;) ). By .kvp. the pointer is directly saved without duplicating any memory.

The nice thing is that it is fortran90 compliant.

like image 29
nickpapior Avatar answered Oct 07 '22 00:10

nickpapior