208
def get_matching_blocks(self):
209
"""Return list of triples describing matching subsequences.
211
Each triple is of the form (i, j, n), and means that
212
a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in
215
The last triple is a dummy, (len(a), len(b), 0), and is the only
218
>>> s = SequenceMatcher(None, "abxcd", "abcd")
219
>>> s.get_matching_blocks()
220
[(0, 0, 2), (3, 2, 2), (5, 4, 0)]
222
# jam 20060525 This is the python 2.4.1 difflib get_matching_blocks
223
# implementation which uses __helper. 2.4.3 got rid of helper for
224
# doing it inline with a queue.
225
# We should consider doing the same for recurse_matches
227
if self.matching_blocks is not None:
228
return self.matching_blocks
229
self.matching_blocks = []
230
la, lb = len(self.a), len(self.b)
231
self.__helper(0, la, 0, lb, self.matching_blocks)
232
self.matching_blocks.append( (la, lb, 0) )
233
return self.matching_blocks
208
235
def __helper(self, alo, ahi, blo, bhi, answer):
210
237
a = self.a[alo:ahi]