Using flat-file database and FileHashMap class
Code: "io_filehashmap.py". Programming language: Python DMelt Version 1. Last modified: 09/05/2015. License: Pro
https://datamelt.org/code/cache/io_filehashmap_455.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



from jhplot import *
from org.clapper.util.misc import FileHashMap 
 
# make some massive java objects
p1=P0D(); p1.randomNormal(10000,0,2)
p2=P0D(); p2.randomNormal(10000,1,2)
pp=P1D("test",p1,p2);  h1=H1D("OK",100,0,10)
ppp=PND(); ppp.add([1,2,3,4,5]); ppp.add([1,2,3,4,3])
 
######### store all objects in the file
print "Write  to the database"
map=FileHashMap("/tmp/mytest",FileHashMap.FORCE_OVERWRITE);
map.put("d1",p1)
map.put("d2",p2)
map.put("d3",ppp)
map.put("4",h1)
print map.size()
map.save()
map.close()
print "Closed   database"


map=FileHashMap("/tmp/mytest",FileHashMap.RECLAIM_FILE_GAPS);
p1=map.get("d1")
p2=map.get("d2")
ppp=map.get("d3")
hh=map.get("4")
print hh
print ppp
print map.size()
map.close()
print "Closed   database"

Ads help maintain this website.