1.1 --- a/simplex/__init__.py Mon Oct 03 00:17:53 2011 +0200
1.2 +++ b/simplex/__init__.py Mon Oct 03 00:34:30 2011 +0200
1.3 @@ -32,6 +32,18 @@
1.4 from simplex.indexers import *
1.5 import bisect
1.6
1.7 +class IndexedFile:
1.8 +
1.9 + "An indexed file referring to a sorted file."
1.10 +
1.11 + def __init__(self, reader, index_reader, get_key):
1.12 + self.reader = reader
1.13 + self.index_reader = index_reader
1.14 + self.get_key = get_key
1.15 +
1.16 + def find(self, term):
1.17 + return find_with_index(self.reader, self.get_key, self.index_reader, term)
1.18 +
1.19 def find_with_index(reader, get_key, l, term):
1.20
1.21 """
2.1 --- a/test_indexed.py Mon Oct 03 00:17:53 2011 +0200
2.2 +++ b/test_indexed.py Mon Oct 03 00:34:30 2011 +0200
2.3 @@ -14,6 +14,7 @@
2.4
2.5 f = open(filename)
2.6 accessor = DelimitedRecord(fields, numeric=(numeric == "true"))
2.7 +
2.8 try:
2.9 t = time.time()
2.10 l = make_index(f, accessor.get_key, int(interval))
2.11 @@ -21,9 +22,17 @@
2.12
2.13 # Now use the index.
2.14
2.15 + index = IndexedFile(f, l, accessor.get_key)
2.16 for term in terms:
2.17 +
2.18 + # Convert the term to the appropriate type.
2.19 +
2.20 + term = accessor.convert(term)
2.21 +
2.22 + # Perform the search.
2.23 +
2.24 t = time.time()
2.25 - line = find_with_index(f, accessor.get_key, l, accessor.convert(term))
2.26 + line = index.find(term)
2.27 if line:
2.28 print "Found (at %s seconds)...\n%s" % (time.time() - t, line)
2.29
3.1 --- a/test_read.py Mon Oct 03 00:17:53 2011 +0200
3.2 +++ b/test_read.py Mon Oct 03 00:34:30 2011 +0200
3.3 @@ -30,9 +30,18 @@
3.4
3.5 # Now use the index.
3.6
3.7 + index = IndexedFile(f, l, accessor.get_key)
3.8 +
3.9 for term in terms:
3.10 +
3.11 + # Convert the term to the appropriate type.
3.12 +
3.13 + term = accessor.convert(term)
3.14 +
3.15 + # Perform the search.
3.16 +
3.17 t = time.time()
3.18 - line = find_with_index(f, accessor.get_key, l, accessor.convert(term))
3.19 + line = index.find(term)
3.20 if line:
3.21 print "Found (at %s seconds)...\n%s" % (time.time() - t, line)
3.22
4.1 --- a/test_scan.py Mon Oct 03 00:17:53 2011 +0200
4.2 +++ b/test_scan.py Mon Oct 03 00:34:30 2011 +0200
4.3 @@ -14,12 +14,20 @@
4.4
4.5 f = open(filename)
4.6 accessor = DelimitedRecord(fields, numeric=(numeric == "true"))
4.7 +
4.8 try:
4.9 for term in terms:
4.10 +
4.11 + # Convert the term to the appropriate type.
4.12 +
4.13 + term = accessor.convert(term)
4.14 +
4.15 + # Perform the search.
4.16 +
4.17 f.seek(0)
4.18
4.19 t = time.time()
4.20 - line = find_in_file(f, accessor.get_key, accessor.convert(term))
4.21 + line = find_in_file(f, accessor.get_key, term)
4.22 if line:
4.23 print "Found (at %s seconds)...\n%s" % (time.time() - t, line)
4.24 finally: