MCPcopy Index your code
hub / github.com/RustPython/RustPython / quick_ratio

Method quick_ratio

Lib/difflib.py:622–649  ·  view source on GitHub ↗

Return an upper bound on ratio() relatively quickly. This isn't defined beyond that it is an upper bound on .ratio(), and is faster to compute.

(self)

Source from the content-addressed store, hash-verified

620 return _calculate_ratio(matches, len(self.a) + len(self.b))
621
622 def quick_ratio(self):
623 """Return an upper bound on ratio() relatively quickly.
624
625 This isn't defined beyond that it is an upper bound on .ratio(), and
626 is faster to compute.
627 """
628
629 # viewing a and b as multisets, set matches to the cardinality
630 # of their intersection; this counts the number of matches
631 # without regard to order, so is clearly an upper bound
632 if self.fullbcount is None:
633 self.fullbcount = fullbcount = {}
634 for elt in self.b:
635 fullbcount[elt] = fullbcount.get(elt, 0) + 1
636 fullbcount = self.fullbcount
637 # avail[x] is the number of times x appears in 'b' less the
638 # number of times we've seen it in 'a' so far ... kinda
639 avail = {}
640 availhas, matches = avail.__contains__, 0
641 for elt in self.a:
642 if availhas(elt):
643 numb = avail[elt]
644 else:
645 numb = fullbcount.get(elt, 0)
646 avail[elt] = numb - 1
647 if numb > 0:
648 matches = matches + 1
649 return _calculate_ratio(matches, len(self.a) + len(self.b))
650
651 def real_quick_ratio(self):
652 """Return an upper bound on ratio() very quickly.

Callers 2

get_close_matchesFunction · 0.95

Calls 3

_calculate_ratioFunction · 0.85
lenFunction · 0.85
getMethod · 0.45

Tested by 1