Skip to content

Commit c1470ad

Browse files
committed
minor changes
1 parent 07f3db0 commit c1470ad

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Lib/difflib.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
Match = _namedtuple('Match', 'a b size')
3939

4040

41-
class _LCSUBDict:
42-
"""Dict method for finding longest common substring.
41+
class _LCSUBSimple:
42+
"""Simple dict method for finding longest common substring.
4343
4444
Complexity:
4545
T: O(n1 + n2) best, O(n1 × n2) worst
@@ -481,18 +481,18 @@ def __chain_b(self):
481481

482482
self._max_bcount = max(bcounts.values()) if bcounts else 0
483483
self._all_junk = frozenset(junk | popular)
484-
self._lcsub_aut = None # _LCSUBAutomaton instance
485-
self._lcsub_dict = None # _LCSUBDict instanct
484+
self._lcsub_automaton = None # _LCSUBAutomaton instance
485+
self._lcsub_simple = None # _LCSUBSimple instanct
486486

487487
def _get_lcsub_calculator(self, automaton=False):
488488
if automaton:
489-
if self._lcsub_aut is None:
490-
self._lcsub_aut = _LCSUBAutomaton(self.b, self._all_junk)
491-
return self._lcsub_aut
489+
if self._lcsub_automaton is None:
490+
self._lcsub_automaton = _LCSUBAutomaton(self.b, self._all_junk)
491+
return self._lcsub_automaton
492492
else:
493-
if self._lcsub_dict is None:
494-
self._lcsub_dict = _LCSUBDict(self.b, self._all_junk)
495-
return self._lcsub_dict
493+
if self._lcsub_simple is None:
494+
self._lcsub_simple = _LCSUBSimple(self.b, self._all_junk)
495+
return self._lcsub_simple
496496

497497
@property
498498
def b2j(self):
@@ -574,7 +574,9 @@ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
574574
# For that specific set it gave selection accuracy of 95%.
575575
# Weak spot in this is cases with little or no element overlap at all.
576576
# However, such check would have more cost than benefit.
577-
use_automaton = self._max_bcount * asize > bsize * 6 + asize * 2
577+
automaton_cost = bsize * 6 + asize * 2
578+
simple_cost = self._max_bcount * asize
579+
use_automaton = simple_cost > automaton_cost
578580
calc = self._get_lcsub_calculator(use_automaton)
579581
besti, bestj, bestsize = calc.find(a, alo, ahi, blo, bhi)
580582

0 commit comments

Comments
 (0)