1.1 --- a/simplex/__init__.py Sat Oct 29 00:30:20 2011 +0200
1.2 +++ b/simplex/__init__.py Sun Apr 21 22:04:07 2013 +0200
1.3 @@ -49,8 +49,8 @@
1.4 """
1.5 In the resource whose 'reader' provides records, using a 'get_key' operation
1.6 to yield the key for such records, and using the given index list 'l', find
1.7 - the given 'term', returning a record employing the term or None if no such
1.8 - record was found.
1.9 + the given 'term', returning all records employing the term or an empty list
1.10 + if no such records were found.
1.11 """
1.12
1.13 i = bisect.bisect_left(l, (term, None))
1.14 @@ -58,7 +58,7 @@
1.15 try:
1.16 found, pos = l[i]
1.17 except IndexError:
1.18 - return None
1.19 + return []
1.20
1.21 # Since the index is more coarse than the underlying file, the bisect left
1.22 # operation will most likely point to an index entry for later records than
1.23 @@ -69,31 +69,29 @@
1.24 found, pos = l[i]
1.25
1.26 reader.seek(pos)
1.27 -
1.28 - if found == term:
1.29 - return reader.next()
1.30 - else:
1.31 - return find_in_file(reader, get_key, term)
1.32 + return find_in_file(reader, get_key, term)
1.33
1.34 def find_in_file(reader, get_key, term):
1.35
1.36 """
1.37 In the resource whose 'reader' provides records, using a 'get_key' operation
1.38 - to yield the key for such records, find the given 'term', returning a record
1.39 - employing the term or None if no such record was found.
1.40 + to yield the key for such records, find the given 'term', returning all
1.41 + records employing the term or an empty list if no such records were found.
1.42 """
1.43
1.44 + results = []
1.45 +
1.46 for record in reader:
1.47 key = get_key(record)
1.48 if term == key:
1.49 - return record
1.50 + results.append(record)
1.51
1.52 # Short-circuit failed searches.
1.53
1.54 elif term < key:
1.55 - return None
1.56 + break
1.57
1.58 - return None
1.59 + return results
1.60
1.61 def groups(l, length):
1.62