Filling a hash view
Marcin Krol <mrkafk <at> gmail.com>
2010-03-04 19:37:48 GMT
Hello everyone,
I'm "testdriving" metakit 4 py now, and I have a little trouble with
hashed view: when the number of keys in view starts exceeding 2000,
filling up a hash view becomes extremely slow.
Is there some way to fill a view that is hashed to begin with, so the db
knows its way around db and adding rows becomes faster?
The code is below.
Also, could someone please explain to me what's the meaning of 'del
map[:]' in
def hash_ini(n=1000):
t0 = time();
for i in xrange(n):
del map[:]
vwh = vw.hash(map)
print ' hash_ini %d times, size %d: %g sec' % (n, len(map), time() - t0)
in examples/find.py in metakit distribution? And why vw.hash(map) has to
be repeated n times? Sadly, the docs do not explain what's this all about.
#!/usr/bin/python
##import wingdbstub
import Mk4py, sys
mk = Mk4py
print sys.argv[0], '- Mk4py', mk.version, '-', sys.platform
db = mk.storage("demo2.db",1)
vw = db.getas('words[idxs1:S,idxs2:S,idxi:I,val:S]')
map = db.getas('map[_H:I,_R:I]')
vwh = None
def fillit():
num = 0
for line in open('testfile.txt'):
vw.append(val=line, idxs1=line[:2].lower(),
idxs2=line[2:4].lower(), idxi=num)
num +=1
if num % 1000 == 0:
print num
db.commit()
def fillithash():
num = 0
for line in open('testfile.txt'):
vw.append(val=line, idxs1=line[:2].lower(),
idxs2=line[2:4].lower(), idxi=num)
num +=1
if num % 1000 == 0:
print num
print map
for i in xrange(num-1):
del map[:]
vwh = vw.hash(map)
if i % 100 == 0:
print i
db.commit()
def selall():
vwh = vw.hash(map)
for r in vwh:
pass
if __name__ == "__main__":
fillithash()
selall()
--
--
You received this message because you are subscribed to the "metakit" group.
To post to this group, send email to metakit <at> googlegroups.com
To unsubscribe from this group, send email to metakit-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/metakit?hl=en