1.1 --- a/simplex/__init__.py Sat Oct 01 16:01:22 2011 +0200
1.2 +++ b/simplex/__init__.py Sat Oct 01 16:40:29 2011 +0200
1.3 @@ -31,13 +31,12 @@
1.4 from simplex.readers import *
1.5 import bisect
1.6
1.7 -def make_index(reader, accessor, interval):
1.8 +def make_index(reader, interval):
1.9
1.10 """
1.11 - Index a resource whose 'reader' provides records and whose 'accessor' can
1.12 - yield the key for such records, creating an index entry for a record after a
1.13 - given number of records, defined by 'interval', have been read since the
1.14 - last entry was produced.
1.15 + Index a resource whose 'reader' provides records and keys, creating an index
1.16 + entry for a record after a given number of records, defined by 'interval',
1.17 + have been read since the last entry was produced.
1.18 """
1.19
1.20 l = []
1.21 @@ -46,8 +45,7 @@
1.22 current_key = None
1.23 start_pos = 0
1.24
1.25 - for i, record in enumerate(reader.get_records()):
1.26 - key = accessor.get_key(record)
1.27 + for i, (key, record) in enumerate(reader.get_records()):
1.28
1.29 # Where duplicate keys are permitted, the first record employing the key
1.30 # must be available as an index entry. Otherwise, records preceding the
1.31 @@ -65,13 +63,12 @@
1.32
1.33 return l
1.34
1.35 -def find_with_index(reader, accessor, l, term):
1.36 +def find_with_index(reader, l, term):
1.37
1.38 """
1.39 - Find in the resource whose 'reader' provides records and whose 'accessor'
1.40 - can yield the key for such records, using the given index list 'l', the
1.41 - given 'term', returning a record employing the term or None if no such
1.42 - record was found.
1.43 + In the resource whose 'reader' provides records and keys, using the given
1.44 + index list 'l', find the given 'term', returning a record employing the term
1.45 + or None if no such record was found.
1.46 """
1.47
1.48 i = bisect.bisect_left(l, (term, None))
1.49 @@ -90,18 +87,17 @@
1.50 found, pos = l[i]
1.51
1.52 reader.seek(pos)
1.53 - return find_in_file(reader, accessor, term)
1.54 + return find_in_file(reader, term)
1.55
1.56 -def find_in_file(reader, accessor, term):
1.57 +def find_in_file(reader, term):
1.58
1.59 """
1.60 - Find in the resource whose 'reader' provides records and whose 'accessor'
1.61 - can yield the key for such records, the given 'term', returning a record
1.62 - employing the term or None if no such record was found.
1.63 + In the resource whose 'reader' provides records and keys, find the given
1.64 + 'term', returning a record employing the term or None if no such record was
1.65 + found.
1.66 """
1.67
1.68 - for record in reader.get_records():
1.69 - key = accessor.get_key(record)
1.70 + for key, record in reader.get_records():
1.71 if term == key:
1.72 return record
1.73