1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test_read.py Mon Oct 03 00:17:53 2011 +0200
1.3 @@ -0,0 +1,43 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from simplex import *
1.7 +import sys, time
1.8 +
1.9 +def from_index_record(convert, record):
1.10 + values = record.split("\t")
1.11 + key = convert(values[:-1])
1.12 + pos = int(values[-1])
1.13 + return key, pos
1.14 +
1.15 +try:
1.16 + separator = sys.argv.index("--")
1.17 + filename, numeric, index_filename = sys.argv[1:4]
1.18 + fields = map(int, sys.argv[4:separator])
1.19 + terms = groups(sys.argv[separator+1:], len(fields))
1.20 + numeric = numeric == "true"
1.21 +except (IndexError, ValueError):
1.22 + print >>sys.stderr, "Usage: %s <filename> <numeric> <index> <field>... -- <term value>..." % sys.argv[0]
1.23 + sys.exit(1)
1.24 +
1.25 +f = open(filename)
1.26 +fi = open(index_filename)
1.27 +accessor = DelimitedRecord(fields, numeric=numeric)
1.28 +
1.29 +try:
1.30 + t = time.time()
1.31 + l = [from_index_record(accessor.convert, record) for record in fi]
1.32 + print "Read index (at %s seconds, with %d entries)." % (time.time() - t, len(l))
1.33 +
1.34 + # Now use the index.
1.35 +
1.36 + for term in terms:
1.37 + t = time.time()
1.38 + line = find_with_index(f, accessor.get_key, l, accessor.convert(term))
1.39 + if line:
1.40 + print "Found (at %s seconds)...\n%s" % (time.time() - t, line)
1.41 +
1.42 +finally:
1.43 + f.close()
1.44 + fi.close()
1.45 +
1.46 +# vim: tabstop=4 expandtab shiftwidth=4