MCPcopy Index your code
hub / github.com/expr-lang/expr / QuickRatio

Method QuickRatio

internal/difflib/difflib.go:480–506  ·  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.

()

Source from the content-addressed store, hash-verified

478// This isn't defined beyond that it is an upper bound on .Ratio(), and
479// is faster to compute.
480func (m *SequenceMatcher) QuickRatio() float64 {
481 // viewing a and b as multisets, set matches to the cardinality
482 // of their intersection; this counts the number of matches
483 // without regard to order, so is clearly an upper bound
484 if m.fullBCount == nil {
485 m.fullBCount = map[string]int{}
486 for _, s := range m.b {
487 m.fullBCount[s] = m.fullBCount[s] + 1
488 }
489 }
490
491 // avail[x] is the number of times x appears in 'b' less the
492 // number of times we've seen it in 'a' so far ... kinda
493 avail := map[string]int{}
494 matches := 0
495 for _, s := range m.a {
496 n, ok := avail[s]
497 if !ok {
498 n = m.fullBCount[s]
499 }
500 avail[s] = n - 1
501 if n > 0 {
502 matches += 1
503 }
504 }
505 return calculateRatio(matches, len(m.a)+len(m.b))
506}
507
508// Return an upper bound on ratio() very quickly.
509//

Callers 2

TestSequenceMatcherRatioFunction · 0.80

Calls 1

calculateRatioFunction · 0.85

Tested by 2

TestSequenceMatcherRatioFunction · 0.64